- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Removing field separators in a txt file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 11:05 PM
05-13-2002 11:05 PM
I have a text file as in:
avbg,yuyu,ppp,ii,
jkdsk,opop,ye82,jj,
jkds,llkl ....(and more...)
Is there a utility in UNIX which moves each entries that are separated by the commas to a new line, by discarding the commas, besides using AWK...??
If so, please provide an example.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 11:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 11:15 PM
05-13-2002 11:15 PM
Re: Removing field separators in a txt file
:g/,/s//^M/g
The ^M is CTRL-V CTRL-M
Or with sed:
cat your_file | tr "," "\012"
Regards,
Trond
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 11:39 PM
05-13-2002 11:39 PM
Re: Removing field separators in a txt file
For Your interest
file=$1
export IFS=,
cat $file|while read line
do
for f in $line
do
echo $f
done
done
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 12:09 AM
05-14-2002 12:09 AM
Re: Removing field separators in a txt file
Well, you did say besides AWK, so here's a perl method:
cat file|perl -F, -ane 'foreach $f (@F){chomp $f;print "$f\n"};'
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 01:28 AM
05-14-2002 01:28 AM
Re: Removing field separators in a txt file
the fastest way is to use tr:
tr ',' '\n' < oldfile > newfile
If you are allready in vi to do some more work on this file:
:1,$s/,/^M/g
Hope this helps
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 05:57 AM
05-14-2002 05:57 AM
Re: Removing field separators in a txt file
Here's the sed method:
sed 's/,//g' file
Note that it is actually entered as 2 lines whether in a script or from a shell prompt (command line).
"tr" is faster. Also note the difference with and without tr's "-s" option. With "-s", repeated characters to be translated (commas in your case) are treated as one occurance. That is, consecutive commas will be replaced with one newline. Without "-s", each comma will be replaced with a newline.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 07:17 AM
05-14-2002 07:17 AM
Re: Removing field separators in a txt file
use @F in string context and set it's separator to the newline:
perl -naF, -e '$"="\n";print"@F"'
shorter and more obfuscated (set list separator to default input record separator):
perl -naF, -e '$"=$/;print"@F"'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 09:07 AM
05-14-2002 09:07 AM
Re: Removing field separators in a txt file
I keep forgetting that 2 line sed examples don't get posted correctly. Didn't check my reply until now. It should look more like:
sed 's/,/
/g' file
There should be a "\" character at the end of the first line.
Please see the attached.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 09:39 AM
05-14-2002 09:39 AM
Re: Removing field separators in a txt file
This note is just to remind you to assign points to the forum members who have been responding to your questions (you have at least 3 thread open currently). It would not only be nice for them since they have been helping you but also be helpful for others to know whether your problem has been solved or not.
Thanks!
Mahima