List into one line?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List into one line?
# 1  
Old 12-09-2011
List into one line?

Probably, something really easy to do and stupid to ask help with it, but how to turn a list of numbers into one line of numbers.

I have:
Code:
, 116332682         
, 116332683         
, 116332685         
, 116332686         
, 116332687         
, 116332688         
, 116332689         
, 116332691

I need:
Code:
, 116332682, 116332683, 116332685, 116332686, 116332687, 116332688, 116332689, 116332691

I tried to cut, sed functions but they weren't right probably, and the unix is not really my thing Smilie

Thanks for any help.

Last edited by Scott; 12-09-2011 at 01:46 PM.. Reason: Code tags
# 2  
Old 12-09-2011
line-based things like cut and sed won't do what you want, because they're line-based. They don't consider \n part of the line, they process it separately.

tr operates on individual characters, not lines. -d means 'delete'. This deletes all newlines.
Code:
tr -d '\n' < infile > outfile

# 3  
Old 12-09-2011
or :
Code:
cat list| xargs

P.S.
Next time, use code tags for your data and code!
This User Gave Thanks to vbe For This Post:
# 4  
Old 12-09-2011
Didn't know xargs could do that. Smilie Neat.
# 5  
Old 12-10-2011
Thank you Smilie ..

code tags??
# 6  
Old 12-11-2011
Quote:
Originally Posted by Iifa
Thank you Smilie ..

code tags??
How to Use Code Tags in The UNIX and Linux Forums
# 7  
Old 12-11-2011
try with AWK...
Code:
echo ",1
 ,2
 ,3
 ,4" |  awk '{for(i=1;i<=NF;i++){print $i}}' FS="\n" RS="" ORS=""

with SED
Code:
echo "
 ,1
 ,2
 ,3" |  sed -n '
 $ !{
 H
 }
 $ {
 H
 x;s/\n//g
 p
 }'


Last edited by Scott; 12-12-2011 at 01:42 AM.. Reason: Code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files output only for the last line

Hi, "ls -tl directory1" will list files to be sorted in mtime, but I don't want to see all the files in each directory, I want to only see output the last line (the oldest mtime) for each directory. $ ls -tl test1 -rw-r--r-- 1 hce hce 1714397 May 30 2013 b.txt -rw-r--r-- 1 hce hce 4678 May... (2 Replies)
Discussion started by: hce
2 Replies

2. Shell Programming and Scripting

List second line entries

Hello everyone, I have a list of new empolyee by year. ( list of employess can be more one than a line) this is my list format # cat mylist.txt 2009 new hire mike noah vaar 2010 new hire 2011 new hire sara phill mike bob tala ali zula 2012 new hire I would like a to have a... (8 Replies)
Discussion started by: Sara_84
8 Replies

3. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

4. Shell Programming and Scripting

turn list into one line

Hi All i am cat'ing a file and then using cut to get rid of some info, is there a way to turn the list into one line i.e 1 2 3 4 5 into 1 2 3 4 5 (4 Replies)
Discussion started by: ab52
4 Replies

5. UNIX for Dummies Questions & Answers

Appending lines from an existing list to each line in another existing list

Evening all ! I would like to ask your expertise on how to accomplish the following ; I have 2 lists, and would like each line from list2 to be appended to each line in list1, resulting in list3 ; List1; alpha beta charlie List2; one two three (4 Replies)
Discussion started by: TAPE
4 Replies

6. Shell Programming and Scripting

Create list in command line

How do you create lists or arrays in the command line? And how do you access specific cells of the list? (1 Reply)
Discussion started by: locoroco
1 Replies

7. Shell Programming and Scripting

how do I list my values one per line instead of across it?

I want to list my vars in a script so they look like while read IN var1 var2 var3 var4 do echo $IN done Then in the same script have them read and processed. the closest I can get is as follows but this is obviously wrong. NOTE I want a list not all the entries on one line, that... (5 Replies)
Discussion started by: pobman
5 Replies

8. UNIX and Linux Applications

Need to list pattern only not containing whole line

I am searching a pattern item_id>000111111</item_id> in an XML file. More than one occurance are there for this patter in a single line. I have tried awk '/item_id/,/item_id/' tpnb1.txt>abc.txt Full lines containg pattern are coming. I need only list of 000111111. (1 Reply)
Discussion started by: tredev
1 Replies

9. Shell Programming and Scripting

i want to list all command line arguments except

Hi all i want to list out all command line arguments except $1 i have passed to a script. Ex: sh cmdline.sh one two three four five o/p: two three four five (3 Replies)
Discussion started by: naree
3 Replies

10. UNIX for Dummies Questions & Answers

converting a list into a line

Hi, this is a pretty intersting problem, I would like to convert a list of words into a concatenated string of words with whitespace between each word. e.g file list :- hello how are you today convert into hello how are you today. What command would I use to do this? Thanks (2 Replies)
Discussion started by: zulander
2 Replies
Login or Register to Ask a Question