Following may help you in same.
1st:
2nd:
Output will be as follows in both above codes. NOTE: considering that the first line space which you have showed us in the sample output is a typo here.
Thanks,
R. Singh
Last edited by RavinderSingh13; 12-31-2015 at 03:24 AM..
Reason: Added a note for user.
This User Gave Thanks to RavinderSingh13 For This Post:
Following may help you in same.
1st:
2nd:
Output will be as follows in both above codes. NOTE: considering that the first line space which you have showed us in the sample output is a typo here.
Thanks,
R. Singh
Yeah that was a Typo.
I shall try it, hope it should work. (not sure about gsub etc.. im learning awk and unix shell scripting)
[...]not sure about gsub etc.. im learning awk and unix shell scripting)
Awk has two built-in functions to deal with string substitutions: sub() and gsub(). There are others built-ins functions for matching and extracting parts of substrings, but these are for substitutions. The main different between both is that sub() will only do the substitution one time on the first instance of the match, and gsub() will do it for every instance of the match; the g in front tries to detonate this distinction and stand for global as in all or the whole.
The syntax could be expressed as gsub(regex, replacement, string), where regex is an Extended Regular Expression to match, replacement is the substitution part and string is the sequence of characters you want the work to be done on.
Using the example given by RavinderSingh13:
In gsub(), now we know: /\,/ is the regex representing the comma we want to find " " is what we want to substitute for $0 is the range of characters we want to work on, in this case the whole record.
After the function is done: print is for after the substitutions are done, display the whole modified record.
However, awk users are attracted by the terse and brief statement abilities that the language has to offer and how much does with so little user code, thus they thrive in applying the most idiomatic and succinct expressions possible. Don't be surprise if you see instead of:
this:
or even
The original command and these two latest produce the same output, in this case.
Or instead of:
this:
Last edited by Aia; 12-31-2015 at 03:00 PM..
Reason: Add more
Note that, although it works with the sample data provided, the last suggestion above will delete lines found in file that have an empty 1st field or have a 1st field that is just a string of one or more 0 characters. The following idiom is safer if either of these could be present in your input:
This User Gave Thanks to Don Cragun For This Post:
Hi, I have a rquirement in unix as below .
I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column.
ex:
Input Text file:
1|A|apple
2|B|bottle
excel file to be generated as output as... (9 Replies)
Hello,
I have a text file with space and tab (mixed) delimited file and need to convert into CSV.
# cat test.txt
/dev/rmt/tsmmt32 HP Ultrium 6-SCSI J3LZ 50:03:08:c0:02:72:c0:b5 F00272C0B5 0/0/6/1/1.145.17.255.0.0.0 /dev/rmt/c102t0d0BEST
/dev/rmt/tsmmt37 ... (6 Replies)
Thank you for 4 looking this post.
We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working.
In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below.
I... (12 Replies)
Hi How to make tab delimited file to space delimited?
in put file:
ABC kgy
jkh ghj
ash kjl
o/p file:
ABC kgy
jkh ghj
ash kjl
Use code tags, thanks. (1 Reply)
Hi,
I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use
cat file | sed 's/|//t/g'
The above command substituted "/t" not tab in the place of pipe.
Sample file:
abc|123|2012-01-30|2012-04-28|xyz
have to convert to:
abc 123... (6 Replies)
Hi,
I have the following code:
LIST=`ls | grep '.sql$'`
echo $LIST
The above code will give me something like..
file1.sh file2.sh file3.sh file4.sh file5.sh
I want to display the values into rows using echo like...
file1.sh
file2.sh (5 Replies)
I have a folder that contains say 50 files in a sequential order:
cdf_1.txt
cdf_2.txt
cdf_3.txt
cdf_3.txt
.
.
.
cdf_50.txt.
I need to merge these files in the same order into a single tab delimited file.
I used the following shell script:
for x in {1..50};
do cat cdf_${x}.txt >>... (3 Replies)
Hi all,
I have a file with single white space delimited values, I want to convert them to a tab delimited file.
I tried sed, tr ... but nothing is working.
Thanks,
Rajeevan D (16 Replies)