![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Formatted Output | dhanamurthy | Shell Programming and Scripting | 6 | 05-12-2008 11:30 PM |
| Formatted output - awk | dhanamurthy | Shell Programming and Scripting | 3 | 05-11-2008 08:25 PM |
| abt viewing all the columns in the output as it is.. | RRVARMA | UNIX for Advanced & Expert Users | 1 | 03-13-2008 07:46 AM |
| formatted output with commas | joeyg | Shell Programming and Scripting | 4 | 03-04-2008 11:54 AM |
| Formatted output in KSH | psynaps3 | Shell Programming and Scripting | 1 | 07-05-2006 05:03 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
cut - columns with formatted Output
Hi
I have the input file as below Code:
***TEST10067 00567GROSZ 099 00567CTCTSDS90 ***TEST20081 08233GROZWEWE 00782GWERW899 ***TEST30088 08233GROZWEWE 00782GWERW899 Code:
TEST10067 TEST20081 TEST30088 grep ^\* 100109.C|cut -c 4-8,' ',9-12 I tried with the above. Is there anyway to format the output with a space. as i am not getting the desired results. Regards Dhana Last edited by Yogesh Sawant; 05-17-2008 at 02:27 AM. Reason: added code tags |
| Forum Sponsor | ||
|
|
|
|||
|
cut - output in formatted way
Hi
I got the output as below $ sed -n '/^*/!d;s/\*\*\*\([A-Z]*\)\([0-9]*\)/\1 \2/p' filename TEST1 0067*01 TEST2 0081*02 TEST3 0088*03 I need only TEST1 0067 TEST2 0081 TEST3 0088 and not *01,*02 and *03. I am trying it out. Meanwhile is there any other simplest way of doing it. Regards Dhana |
|
|||
|
ruby one liner
If your input is indeed fixed width, here's a one-liner in ruby:
Code:
$ ruby -e 'STDIN.readlines.each { |l| puts "#{l[3..7]} #{l[8..-1]}" if l[0..2] == "***" }' <filename
Code:
python -c 'import sys; print "\n".join([ "%s %s" % (l[3:7], l[8:-1]) for l in sys.stdin.readlines() if l[0:3] == "***" ])' <filename Code:
awk '/^\*\*\*/ { print(substr($1,4,5), substr($1,9,10)); }' <filename
Q |
|
|||
|
Hi
The awk looks good to me and i tried changing on it awk '/^\*\*\*/ { printf "%s %s\n",substr($1,4,5), substr($1,9,4) }' < filename if my file has the following inputs ***BRRAA0067** TESTSS sdfasdf ***SIZZ 0081** sdfas sdfasd ***TYPEE0078** dsfas asdfasdf I am getting the below output BRRAA 0067 SIZZ TYPEE 0078 If you note that SIZZ has only four characters and a space then i am getting the output as shown above. But i need 0081 also coming up after SIZZ . Do any one of you have some idea on what needs to be changed ? REgards Dhana |
|||
| Google UNIX.COM |