nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

C shell scipts

This is a discussion on C shell scipts within the Shell scripting forums, part of the Development/Scripting category; searches for all phone numbers of the forms xxx-xxx-xxxx (x is any digit) in a document file and removes the ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 02-05-2006, 10:36 AM
TOPHUMAN
Guest
 
Posts: n/a
Default C shell scipts

searches for all phone numbers of
the forms xxx-xxx-xxxx (x is any digit) in a document file and removes the area code.
phonebook generates a file called phonelist (with one phone number per line) which
contains all the phone numbers it has found in the document.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-05-2006, 04:34 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Assuming that your file looks like as follows:

FILE.TXT
Code:
123-1122-99959
123-122-99949
123-12-99929
123-11-9999
Then following command can print needed fields
Code:
awk -F'-' '{ print $3 }' FILE.TXT > output.txt
OR
Code:
awk -F'-' '{ print $2"-"$3 }' FILE.TXT > output.txt
Display new file
Code:
less output.txt
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #3 (permalink)  
Old 02-05-2006, 04:47 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

If your file use firstname lastname phone format then you need following code (tab is delimiter):

FILE.TXT
Code:
Monk    Monk    123-1122-9959
Tom     Jerry   123-122-99949
Cat     Mouse   123-12-99929
DEMO    DEMO    123-11-9999
Command:
Code:
awk -F'\t' '{ print $3}' abc | awk -F'-' '{ print $3 }'
If comma (,) is delimiter:
FILE.TXT
Code:
Monk,Monk,123-1122-9959
Tom,Jerry,123-122-99949
Cat,Mouse,123-12-99929
DEMO,DEMO,123-11-9999
Command:
Code:
awk -F',' '{ print $3}' abc | awk -F'-' '{ print $3 }'
You need to give us sample input file to get exact command, otherwise we need to guess it everytime
Reply With Quote
  #4 (permalink)  
Old 02-06-2006, 01:22 AM
TOPHUMAN
Guest
 
Posts: n/a
Default question

Format is xxx-xxx-xxxx first 3 dight is the area code,only remove the area code and proint out
Reply With Quote
  #5 (permalink)  
Old 02-06-2006, 02:38 AM
TOPHUMAN
Guest
 
Posts: n/a
Default still something need to folorrow

need use "sed"
Reply With Quote
  #6 (permalink)  
Old 02-06-2006, 03:16 AM
TOPHUMAN
Guest
 
Posts: n/a
Default THANKS

Thank you everyone
It works fine now !

but how to show up incould name,i only get number!
Reply With Quote
  #7 (permalink)  
Old 02-07-2006, 12:02 PM
Guest
 
Posts: n/a
Default

Can you put your sample input file here so that some1 will write correct command for u

Cheers
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
writing a shell script to find out my shell name jaymob123 Shell scripting 1 10-08-2007 01:36 AM


All times are GMT +5.5. The time now is 07:57 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36