Formatting the lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Formatting the lines
# 1  
Old 01-29-2007
Error 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  
Old 01-29-2007
Code:
#!/bin/sh
# comma.sh

read LINE
echo -n ${LINE}

while read LINE
do
        if [[ ! -z "${LINE}" ]]
        then
                echo -n ",${LINE}"
        fi
done

echo

Code:
$ echo -e "1\n2\n3\n4\n5\n" | ./comma.sh
1,2,3,4,5
$

# 3  
Old 01-29-2007
Please read the rules. Duplicate threads are not permitted.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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. Shell Programming and Scripting

help formatting

I need to format a txt file and convert it in CSV. Any "future" column is separated by a newline. FROM: XS1 1.43294 0.0 XS2 1.21824 0.0 TO: XS1,XS2 (2 Replies)
Discussion started by: alfreale
2 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 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,... (5 Replies)
Discussion started by: ali560045
5 Replies

6. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies

7. 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

8. 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

9. UNIX for Dummies Questions & Answers

formatting

Hi Again Guys , Please i installed linux RH 6.1 on Toshiba , 10G , RAM=128 , 600 MHZ . After i installed linux i got many error messages , seems it was not installed correctly , also when i finished installation it did not ask me for the 2nd installation CD , and when i logged as root , i... (5 Replies)
Discussion started by: tamemi
5 Replies
Login or Register to Ask a Question