Visit Our UNIX and Linux User Community


Read a file content with awk and sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read a file content with awk and sed
# 8  
Old 10-24-2009
Hello ,

Please find the sample data that I using in the attachment.
# 9  
Old 10-24-2009
see the o/p for your sample input file..
Code:
fnsonlu1-/home/> cat sample.txt
06.09.2009 18:07:01 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 18:12:57 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
fnsonlu1-/home/> awk -F"[()]" '{print $2}' sample.txt
0499472147
0499472147
0499472147
0165599574
0165599574
0165599574
0165599574
0499472147
0499472147
0165599574
0165599574
0499472147
fnsonlu1-/home/fnsonlu1>

# 10  
Old 10-24-2009
Is there anything wrong in what I did ?

/usr/people/wrajyasm$ cat sample.txt
06.09.2009 18:07:01 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 18:12:57 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
/usr/people/wrajyasm$ awk -F"[()]" '{print $3}' sample.txt






/usr/people/wrajyasm$
# 11  
Old 10-24-2009
Quote:
Originally Posted by rmv
Code:
awk -F"[()]" '{print $3}' sample.txt

Code:
awk -F"[()]" '{print $2}' sample.txt

# 12  
Old 10-24-2009
cat sample.txt
06.09.2009 18:07:01 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 18:12:57 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
/usr/people/wrajyasm$ awk -F"[()]" '{print $2}' sample.txt






/usr/people/wrajyasm$

Even then I am not getting any output .Please help.
# 13  
Old 10-24-2009
what is wrong ?
Code:
# awk 'BEGIN{FS=")"}{ for (i=1;i<NF;i++){ gsub(/.*\(/,"",$i) ;if($i ~ /[0-9]+/) print $i}}' file
0499472147
0499472147
0499472147
0165599574
0165599574
0165599574
0165599574
0499472147
0499472147
0165599574
0165599574
0499472147

# 14  
Old 10-24-2009
Quote:
Originally Posted by rmv
cat sample.txt
06.09.2009 18:07:01 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
06.09.2009 18:10:37 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 06:02:08 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
07.09.2009 18:20:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:00:52 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 06:05:28 Customer login not found: identifier=(0165599574) prefix=(TEL) serviceCode=().
08.09.2009 18:12:57 Customer login not found: identifier=(0499472147) prefix=(TEL) serviceCode=().
/usr/people/wrajyasm$ awk -F"[()]" '{print $2}' sample.txt






/usr/people/wrajyasm$

Even then I am not getting any output .Please help.
It works perfectly on Solaris.

Did you try nawk as suggested, or /usr/xpg4/bin/awk?

Previous Thread | Next Thread
Test Your Knowledge in Computers #959
Difficulty: Medium
The first virus attack against a Linux machine was by a virus called Stooge,
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed, awk or another bash command to modify string with the content of another file

Hello everybody, I would like modify some strings using sed or another command line with the content file. For example: - {fqdn: "server-01" , ip: "server-01"} - {fqdn: "server-02" , ip: "server-02"} - {fqdn: "server-03" , ip: "server-03"} - {fqdn: "server-04" , ip: "server-04"} My... (4 Replies)
Discussion started by: dco
4 Replies

2. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

3. Shell Programming and Scripting

'Couldn't read file' error in bash script with expect, sed and awk!

Ok, so I have a bash script with an embedded expect statement. Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time. Here's my command: cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies

4. Shell Programming and Scripting

changing files content with sed or awk

Hi, Example File: (jumped, bumped, ) how to jumped, FROM tree; EXIT I have some hundreads of files like this with the different words and I want to remove the comma before the bracket and also I have to remove the comma before FROM word. I am trying to use this command : awk '... (5 Replies)
Discussion started by: rajshashi
5 Replies

5. Shell Programming and Scripting

SED/AWK file read & manipulation

I have large number of data files, close to 300 files, lets say all files are same kind and have extension .dat , each file have mulitple lines in it. There is a unique line in each file containing string 'SERVER'. Right after this line there is another line which contain a string 'DIGIT=0',... (4 Replies)
Discussion started by: sal_tx
4 Replies

6. Shell Programming and Scripting

Read content between xml tags with awk, grep, awk or what ever...

Hello, I trying to extract text that is surrounded by xml-tags. I tried this cat tst.xml | egrep "<SERVER>.*</SERVER>" |sed -e "s/<SERVER>\(.*\)<\/SERVER>/\1/"|tr "|" " " which works perfect, if the start-tag and the end-tag are in the same line, e.g.: <tag1>Hello Linux-Users</tag1> ... (5 Replies)
Discussion started by: Sebi0815
5 Replies

7. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

8. Shell Programming and Scripting

read file content

i have one file abhi.txt its contents are home8/mc09ats/UnixCw/backup/file1 home8/mc09ats/file2 i want to read this content of file using while loop.. in this i want to seperate the content as follows path=home8/mc09ats/UnixCw/backup file=file1 echo path echo file can you... (1 Reply)
Discussion started by: AbhijitIT
1 Replies

9. Shell Programming and Scripting

read a file and use the content for mapping

help me pls.. :( i want to read a mapping file. Below is the content of my mapping file. 6221,189,SMSC1,OMC1,WAP1 6223,188,SMSC2,OMC2,WAP2 so when my program running msisdn="622130302310" while not EOF if substring($msisdn,1,4) == "6221" -- > "6221" read from the file then echo... (0 Replies)
Discussion started by: voidmain
0 Replies

10. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies

Featured Tech Videos