formatting lines in a particular fashion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting formatting lines in a particular fashion
# 1  
Old 10-16-2008
formatting lines in a particular fashion

i have some 100 of lines from a script o/p into a file called naveed.txt
below some of the lines:

1-GH32X, CC, AMR, Number of Intervals Not Inserted: 1 / 95
1-150KP1, CC, AMR, Number of Intervals Not Inserted: 1 / 96
1-VWEMR, CC, AMR, Number of Intervals Not Inserted: 1 / 98
1-15HM1A, CC, AMR, Number of Intervals Not Inserted: 1 / 99
1-153PIV, CC, AMR, Number of Intervals Not Inserted: 3 / 99
1-M7U4D, CC, AMR, Number of Intervals Not Inserted: 1 / 229
1-14ZL4V, CC, AMR, Number of Intervals Not Inserted: 1 / 96
----------------------------------------------------------------------

Actually my requirement is to get these line in the below fashion

1-GH32X|CC|AMR|Number of Intervals Not Inserted: 1 / 95
1-150KP1|CC|AMR|Number of Intervals Not Inserted: 1 / 96
1-VWEMR|CC|AMR|Number of Intervals Not Inserted: 1 / 98
1-15HM1A|CC|AMR|Number of Intervals Not Inserted: 1 / 99
1-153PIV|CC|AMR|Number of Intervals Not Inserted: 3 / 99
1-M7U4D|CC|AMR|Number of Intervals Not Inserted: 1 / 229
1-14ZL4V|CC|AMR|Number of Intervals Not Inserted: 1 / 96

Any help will be appreciated. thanks in advance
# 2  
Old 10-16-2008
Its very easy thing use tr command to do that.
# 3  
Old 10-16-2008
i tried using the below command

cat naveed.txt | head -1 | tr ',' '|'

1-GH32X| CC| AMR| Number of Intervals Not Inserted: 1 / 95
1-150KP1| CC| AMR| Number of Intervals Not Inserted: 1 / 96
1-VWEMR| CC| AMR| Number of Intervals Not Inserted: 1 / 98
1-15HM1A| CC| AMR| Number of Intervals Not Inserted: 1 / 99
1-153PIV| CC| AMR| Number of Intervals Not Inserted: 3 / 99
1-M7U4D| CC| AMR| Number of Intervals Not Inserted: 1 / 229
1-14ZL4V| CC| AMR| Number of Intervals Not Inserted: 1 / 96
1-GULWX| CC| AMR| Number of Intervals Not Inserted: 1 / 96
1-MV44L| CC| AMR| Number of Intervals Not Inserted: 1 / 96

----------------------------------------------------------------------

but getting spaces after |

geting o/p:

1-GH32X| CC| AMR| Number of Intervals Not Inserted: 1 / 95

desired:

1-GH32X|CC|AMR|Number of Intervals Not Inserted: 1 / 95
# 4  
Old 10-16-2008
Tyr this ...

Code:
sed 's/\, /\|/g' naveed.txt

# 5  
Old 10-16-2008
thanks with sed cmd it working fine. i just want it to tune it more

with cmd: sed 's/\, /\|/g' naveed.txt

o/p:

1-GH32X|CC|AMR|Number of Intervals Not Inserted: 1 / 95

how to achive this with some thing in the above sed cmd

1-GH32X|CC|AMR|Number of Intervals Not Inserted:1/95
# 6  
Old 10-16-2008
Try this ...

Code:
sed -e 's/\, /\|/g' -e 's/\ \/\ /\//g' naveed.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

2. UNIX for Advanced & Expert Users

Text formatting - joining lines

I have large file with data as below, in unix using sed or some cammand how to get output as below. cat 1.txt Normal data 1|AA|NN 4|BB|NNN C|DDD|N //Additional details 9C|12C|8N Specific Details 12N|JIN|KK\NY1\ 345\ABC1\KKK 90|ENO0|NDO 17|NO921|NCOKL output shoud be as below ... (10 Replies)
Discussion started by: Tecnical_help12
10 Replies

3. UNIX for Dummies Questions & Answers

Is there any way to add to a tarball made in this fashion

Hello, I am wondering if there is an easy way to add a file to a tarball rather than extracting, adding, then remaking the tarball. The tarball was made in this way: tar -cpvzf .wine.tar.gz .wine/If I had a file to the .wine/ dir (or if I just wanted to add a file to the tarball), I would... (4 Replies)
Discussion started by: Narnie
4 Replies

4. UNIX for Dummies Questions & Answers

Select only certain lines from file and mantain formatting

I want to take the below data, and have it output to file only the STMC#/(IP address) and the "there are X number of updates to install" lines for each machine. I know it's easy, but Im a beginner in BASH stuff, my solution would probably take way too many lines to do something easy.Thanks! ... (5 Replies)
Discussion started by: glev2005
5 Replies

5. Shell Programming and Scripting

Formatting lines in shell script

I have a file with the below lines 1521 1522 1523 1524 1525 1526 ... 174 lines all numbers like above. I want the above file to appear as below. 1521,1522,1523,1524..... All the numbers should be separated by comma. Pls tell me how to do this .... Thanks in advance. (8 Replies)
Discussion started by: dreams5617
8 Replies

6. UNIX for Dummies Questions & Answers

Formatting the lines

I have a file with the below lines 1521 1522 1523 1524 1525 1526 ... 174 lines all numbers like above. I want the above file to appear as below. 1521,1522,1523,1524..... All the numbers should be separated by comma. Pls tell me how to do this .... Thanks in advance. (2 Replies)
Discussion started by: dreams5617
2 Replies

7. Shell Programming and Scripting

Concatenating lines and formatting.

Hi, I have a html file which is unformatted and need to concatenate the lines between each "table" statement in order to run an awk statement on it. Here is the example of the raw file: <table border="0" cellspacing="0" cellpadding="0" class="playerDetails"> def ... (3 Replies)
Discussion started by: Tonka52
3 Replies
Login or Register to Ask a Question