Visit Our UNIX and Linux User Community


convert one colume file to a one line, wrapped file.


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users convert one colume file to a one line, wrapped file.
# 1  
Old 12-02-2008
convert one colume file to a one line, wrapped file.

I need to convert a file i.e
cat list
1000:
1001:
1002:

to
cat wrappedfile 1000:1001:1002:

currently I am using a while loop, paste and mv command to achieve desired outcome.

touch wrappedfile
cat list | while read line ;do echo $line > /tmp/$line;paste /tmp/$line wrappedfile > wrappedfile.tmp;mv wrappedfile.tmp wrappedfile;done > out
cat out
1000: 1001: 1002:

Then to clean it up I pipe it to sed 's/:./:/g' to remove spaces between each #
1000:1001:1002:

It doesn't seem very efficient to me.
Maybe awk or sed or perl has an option or utility to quickly and cleanly get the result I am looking for.

The numbers represent Netbackup (6.5) media that I was to eject using the multi_eject option offered in vmchange command.
vmchange -res -multi_eject -w -verbose -rn 0 -rt tld -rh acuransx -vh acuransx -ml $ejectfile
$ejectfile is variable derived from the output i.e. 1000:1001:1002:

vmchange -res -multi_eject -w -verbose -rn 0 -rt tld -rh acuransx -vh acuransx -ml 1000:1001:1002:

sorry if this is long winded, first time posting
# 2  
Old 12-02-2008
Hammer & Screwdriver Perhaps showing you another way

Code:
> cat file91
1000:
1001:
1002:
> tr "\n" " " <file91 ; echo         
1000: 1001: 1002: 
> tr "\n" " " <file91 >file91n ; echo >>file91n
> cat file91n
1000: 1001: 1002:

# 3  
Old 12-02-2008
Other possibilties:

Code:
tr -d '\n' < file

Code:
awk '{printf $0}' file

Code:
awk '1' ORS= file

Regards
# 4  
Old 12-02-2008
Forgot about tr, use to use it to change lowercase to uppercase a long time ago.
thanks
That still leaves me with a sed command to clean it up. You have definitely reduced the work load by eliminating the while loop.
I did a man on tr and still had a hard time figuring out how your syntax is working in this instance. Could you explain? "\n" " "
can it be used by redirecting output rather than redirecting out from a file as in your example to redirecting output from a script.
script produces one column of output
or does the output from script have to be redirected to a file and then passed to tr?
# 5  
Old 12-02-2008
convert one colume file to a one line, wrapped file.

Franklin52 Other possibilities
I like it
can you expand the last example
awk '1' ORS= file1

I can use the awk examples with script output as well as with file output
thanks

Thank you both.
joeyg and Franklin52

tr -d '\n' < file

ejectmultimedia=`awk '{printf $0}' file91`
Smilieecho $ejectmultimedia
1000:1001:1002:

awk '1' ORS= file

> cat file91
1000:
1001:
1002:
> tr "\n" " " <file91 ; echo
1000: 1001: 1002:
> tr "\n" " " <file91 >file91n ; echo >>file91n
> cat file91n | sed 's/:./:/g'
1000:1001:1002:
# 6  
Old 12-02-2008
Hammer & Screwdriver You don't need sed to remove spaces; modify the command

Code:
> tr -d "\n" <file91 >file91n ; echo >>file91n
> cat file91n
1000:1001:1002:

# 7  
Old 12-02-2008
Or:

Code:
awk '{printf $0}END{print ""}' file > newfile


Previous Thread | Next Thread
Test Your Knowledge in Computers #768
Difficulty: Medium
Smart cache, developed by AMD, is a level 2 or level 3 caching method for multiple execution cores
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print the line that matches and the next if line is wrapped

I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file. caw-enabled ... (3 Replies)
Discussion started by: kieranfoley
3 Replies

2. UNIX for Dummies Questions & Answers

Convert UNIX text file in Windows to recognize line breaks

Hi all, I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this? Or just reinsert thousands of line breaks again :eek: ? (2 Replies)
Discussion started by: frys_hp
2 Replies

3. Windows & DOS: Issues & Discussions

Convert UNIX text file in Windows to recognize line breaks

Hmmm I think I found the correct subforum to ask my question... I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this?... (1 Reply)
Discussion started by: frys_hp
1 Replies

4. Shell Programming and Scripting

How to convert excel file to csv file or text file?

Hi all, I need to find a way to convert excel file into csv or a text file in linux command. The reason is I have hundreds of files to convert. Another complication is the I need to delete the first 5 lines of the excel file before conversion. so for instance input.xls description of... (6 Replies)
Discussion started by: johnkim0806
6 Replies

5. Shell Programming and Scripting

Remove new line character and add space to convert into fixed width file

I have a file with different record length. The file as to be converted into fixed length by appending spaces at the end of record. The length should be calculated based on the record with maximum length in the file. If the length is less than the max length, the spaces should be appended... (4 Replies)
Discussion started by: Amrutha24
4 Replies

6. Shell Programming and Scripting

convert Multiline file in one line file

Hi, Hi, we have one input file and file contain single line and multiline date. We want to convert multiline line in one line. Each file start with sequence of 000000001, 000000002, 000000003 so on. We want to convert the multiline line in one line. All (single line and converted multiline to... (6 Replies)
Discussion started by: humaemo
6 Replies

7. Shell Programming and Scripting

Match a line in File 1 with Column in File 2 and print whole line in file 2 when matched

Hi Experts, I am very new to scripting and have a prb since few days and it is urgent to solve so much appreciated if u help me. i have 2 files file1.txt 9647810043118 9647810043126 9647810043155 9647810043161 9647810043166 9647810043185 9647810043200 9647810043203 9647810043250... (22 Replies)
Discussion started by: mustafa.abdulsa
22 Replies

8. UNIX for Dummies Questions & Answers

how to add a colume with serial # in a file

I am working on a file, I need add a column with serial # in a file, the column will be the first column. and the serial # will be decide by each raw, say if I have 6 raws, I need serial # from 1 to 6 in the first column. Anyone know how to add that. I really appreciate. Thanks (2 Replies)
Discussion started by: sunsnow86
2 Replies

9. Shell Programming and Scripting

Convert comma seperated file to line seperated.

Hi, I have data like this. 1,2,3,4 Output required: 1 2 3 4 I am trying to use tr function but getting error. Help is appreciated. (6 Replies)
Discussion started by: pinnacle
6 Replies

10. UNIX for Dummies Questions & Answers

read a line from a csv file and convert a column to all caps

Hello experts, I am trying to read a line from a csv file that contains '.doc' and print the second column in all caps. e.g. My csv file contains: Test.doc|This is a Test|test1|tes,t2|test-3 Test2.pdf|This is a Second Test| test1|tes,t2|t-est3 while read line do echo "$line" |... (3 Replies)
Discussion started by: orahi001
3 Replies

Featured Tech Videos