Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-24-2013, 11:40 AM   #1
LQ Newbie
Registered: Jul 2013
Posts: 9

Rep: Reputation: Disabled
Separating 1 column into multiple columns


I currently have a file with a column that looks like the following:


I need this to be separated into 5 columns with the ":" marking the separation points.

Any suggestions would be greatly appreciated,


Last edited by mphillips67; 07-24-2013 at 11:42 AM.
Old 07-24-2013, 11:54 AM   #2
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
The "tr" program will zap this for you.
tr : ' ' < myfilename
1 members found this post helpful.
Old 07-24-2013, 12:05 PM   #3
LQ Newbie
Registered: Jul 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
That did the trick, thanks.
Old 07-25-2013, 08:24 AM   #4
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You might also consider giving us bit of wider context for the request. There may be other, better techniques available depending on exactly what you intend to do with the data.

For example, if you are going to process each line in a shell loop, then you could break up each line into separate variables (or an array) with read.

while IFS=':' read -r f1 f2 f3 f4 f5 ; do
    echo "field one is: $f1"
    echo "field two is: $f2"
done <infile.txt
How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?

Similarly, complex work on field-based data is just what awk was designed to do. You may be able to do everything you want in it alone.

Of course, if you really did just want to replace colons with spaces, then carry on.

PS: Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. Thanks.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] lookup from one column in three columns by awk phpshell Programming 8 04-13-2013 12:38 PM
awk split single column into multiple columns based on RS wolverene13 Programming 11 11-01-2012 05:07 PM
how to merge multiple columns into one column linuxon Linux - Newbie 6 03-14-2012 11:17 AM
sort multiple columns + replace another column cedance Linux - Newbie 1 03-29-2011 05:59 AM
How to get parts of one column and prints all columns ? nasra2002 Linux - Software 2 12-13-2010 09:36 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:11 PM.

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