Delete a portion of a line using shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete a portion of a line using shell scripting
# 1  
Old 08-25-2008
Delete a portion of a line using shell scripting

Hi all,
I am new to awk programs.I have a file like this

1234567@2345|[HELLO]|adcbdefhij: asgdfdasdfhhfd-asdfasd-dsfasdf |0.678|0.0|0.213
1234567@2345|[HELLO]|adcbdefhij: ashhfd-asdfasd-dsfasdf |0.129|0.0|0.411
1234567@2345|[HELLO]|adcbdefhij: asd-aasd-dasdf |0.223|0.0|0.276

I want to delete the text which occurs between @ and :
And also is it possible to remove the theses numbers which occur at the end of every line |0.223|0.0|0.276
This is urgent...Any help would be appreciated....

Thanks in Advance
# 2  
Old 08-25-2008
cat $file |sed -e 's/\@.*://' -e 's/\|.*$//'
# 3  
Old 08-25-2008
Code:
awk 'BEGIN{FS="[@:|]"}{ printf "%s%s\n",$1,$5}' file

# 4  
Old 08-25-2008
Thanks a lot to you both! it worked ... the awk gave the exact reslut that i wanted...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all CONSECUTIVE text lines from file shell scripting

Hi I have a text file like below. THe content of the text will vary. Entire text file have four consecutive lines followed with blank line. I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all... (5 Replies)
Discussion started by: RJSKR28
5 Replies

2. Shell Programming and Scripting

Shell to display portion of a line

Thanks a lot for the code and the explanation. Now my final requirement. I have uploaded 3 files as attachment. Please open the files in Editplus or any other text editor which keeps the formatting. GMDCOM.27936.log.txt------I want to pick only Process request from this file.(Please check... (9 Replies)
Discussion started by: ghosh_tanmoy
9 Replies

3. UNIX for Dummies Questions & Answers

Delete a record in a xml file using shell scripting

find pattern, delete line with pattern and 3 lines above and 8 lines below the pattern. The pattern is "isup". The entire record with starting tag <record> and ending tag </record> containing the pattern is to be deleted and the rest to be retained. <record> ... (4 Replies)
Discussion started by: sdesstp
4 Replies

4. Shell Programming and Scripting

Need one line scripting on Unix shell..help!!

Hi Experts, I need one line script for the below requirement. First it should check if a directory with todays date exist, and if not create it and move the PDF file to that directory. thanks in advance!!! (2 Replies)
Discussion started by: eeegopikannan
2 Replies

5. Shell Programming and Scripting

How to compare a command line parameter with -- in shell scripting

Hi, I need to check if a parameter provided at the command line is equal to --.How can i do that ? Please help me. Thanks and Regards, Padmini (4 Replies)
Discussion started by: padmisri
4 Replies

6. Shell Programming and Scripting

Need help in splitting a line into fields in shell scripting

I have a line of more than 3000 bytes which will contain & as fields separator..I am using following awk command ..Its working but its not accepting the line more than 3000 bytes...Anyother alternate solution even in othe shell command also fine... awk -F '&' '{for( i=1; i<=NF; i++ ) print $i}'... (2 Replies)
Discussion started by: punithavel
2 Replies

7. Shell Programming and Scripting

How do i iterate thru each line of a file in shell scripting?

Hi All, I need to execute some commands on each line of a file. How do i iterate thru each line of a file? In detail: First i will have to go to the first line of the file and execute a series of commands on it and then take the second line of the file, execute a series of steps and so... (2 Replies)
Discussion started by: Ravi Varma
2 Replies

8. Shell Programming and Scripting

End of Line in Shell Scripting

I have a file containing records seperated by delimiter '|'.A record is contained on 2 or 3 lines. Now I need a shell script which could write all records with in two '|' character in one line.....for example..... |R1........................R1 R1..........................R1... (2 Replies)
Discussion started by: 33junaid
2 Replies

9. Programming

Delete Portion of a file

hi i would like to know whether i can delete a part of a file in C for eg. if my file contained 1234567890 and i want to delete 456 so that it becomes 1237890 is there a way i can do this. well, one way i can achieve this is by creating a new file, copy whatever i want, then delete the... (2 Replies)
Discussion started by: sameersbn
2 Replies

10. Shell Programming and Scripting

who to deal with whole line in shell scripting

I have a problem in my HP Unix system , it is briefly : I have two files : Myfile and Script.sh : Myfile contain this lines : String1 string2 string3 string5 String1 string2 string3 string5 String1 string2 string3 string5 ... (2 Replies)
Discussion started by: KSA
2 Replies
Login or Register to Ask a Question