LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-15-2021, 09:39 AM   #1
sam_nyc
Member
 
Registered: Aug 2009
Posts: 73

Rep: Reputation: 1
help with xargs and sed


Good morning,

Quick question on xargs and sed. How to change the output of the file to line by line. Pls. see the example below.

Code:
myFile.txt
server1,server2,server3,server4
I want the output to look like this. I don't need the comma and needs to read line by line.
Code:
server1
server2
server3
server4

Code:
cat /tmp/myFile.txt |xargs | sed 's / /,/g'     Not working.
 
Old 12-15-2021, 09:45 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,576
Blog Entries: 19

Rep: Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453
You don't put a pipe after xargs. The way xargs works is it takes its first argument to be the program to run and passes the rest of the arguments to that program. You haven't given xargs any arguments at all!
 
Old 12-15-2021, 09:50 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Why do you need xargs here at all?
Code:
tr , \\n </tmp/myFile.txt
 
2 members found this post helpful.
Old 12-15-2021, 09:55 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
yes, xargs is definitely not the right tool here:
Code:
sed 's/,/\n/g' /tmp/myFile.txt
 
1 members found this post helpful.
Old 12-15-2021, 10:08 AM   #5
sam_nyc
Member
 
Registered: Aug 2009
Posts: 73

Original Poster
Rep: Reputation: 1
Thank you so much to all for your quick help. I learn something new everyday. :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 7 05-21-2014 07:26 PM
Changing data format using sed and Xargs command Hariesh08 Linux - Newbie 3 07-29-2013 03:17 AM
How to use xargs within xargs ? anindyameister Linux - Newbie 1 05-15-2013 05:01 AM
Problem using sed with variable created using xargs - unterminated error wrankin Programming 5 11-14-2011 07:53 PM
Traverse the file system and Rename (xargs or sed?) sahil.jammu Linux - General 19 05-25-2011 10:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration