cut - columns with formatted Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut - columns with formatted Output
# 1  
Old 05-16-2008
cut - columns with formatted Output

Hi
I have the input file as below
Code:
***TEST10067
00567GROSZ 099
00567CTCTSDS90
***TEST20081
08233GROZWEWE
00782GWERW899
***TEST30088
08233GROZWEWE
00782GWERW899

I am finding the lines starting with *** and outputing as below
Code:
TEST10067
TEST20081
TEST30088

I need a space between TEST1 and 0067 and similarly for the other records.

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 07:27 AM.. Reason: added code tags
# 2  
Old 05-17-2008
Code:
$ cat dh.txt
***TEST10067
00567GROSZ 099
00567CTCTSDS90
***TEST20081
08233GROZWEWE
00782GWERW899
***TEST30088
08233GROZWEWE
00782GWERW899

$ sed -n '/^\*/p' dh.txt
***TEST10067
***TEST20081
***TEST30088

$ sed -n '/^\*/p' dh.txt | sed 's/\*\*\*\([A-Z]*\)\([0-9]*\)/\1 \2/'
TEST 10067
TEST 20081
TEST 30088

//Jadu
# 3  
Old 05-17-2008
Might as well condense it into a single sed script.

Code:
sed -n '/^*/!d;s/\*\*\*\([A-Z]*\)\([0-9]*\)/\1 \2/p' dh.txt

# 4  
Old 05-18-2008
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
# 5  
Old 05-19-2008
Code:
awk -F"TEST" '/^\*/{split($2,a,"");print FS a[1], a[2]a[3]a[4]a[5]}' filename

# 6  
Old 05-19-2008
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

And the same sort of thing in python:
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

Or in awk
Code:
awk '/^\*\*\*/ { print(substr($1,4,5),  substr($1,9,10)); }' <filename

--
Q
# 7  
Old 05-19-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script for formatted output

06/26/2017 23:40:40 CAUAJM_I_10082 06/26/2017 23:40:40 CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: STARTING JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14 06/26/2017 23:40:42 CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: RUNNING JOB:... (10 Replies)
Discussion started by: Sandeep Behera
10 Replies

2. Programming

Formatted output in PERL

Hi Techies, I'm a newbie to PERL, Please help me with following problem. I have an input text file like below cat Input.txt 418673132,P 492538858,P 384535478,P 521522357,I 529435679,I 183617024,P 184414408,I 735510689,P 736238343,I 411642045,I 412690979,I 104232783,I (2 Replies)
Discussion started by: mahi_mayu069
2 Replies

3. UNIX for Dummies Questions & Answers

Help creating well-formatted columns

Hi all I'm having a few issues with sorting some data into easily-readable columns. Original data in file: Number of visits IP Address 8 244.44.145.122 8 234.45.165.125 6 225.107.26.10 I firstly tried the column -t command which results in this: Number of ... (4 Replies)
Discussion started by: semaj
4 Replies

4. UNIX for Dummies Questions & Answers

Request for Formatted Output

Can you please tell me how to just get only the output of dealers I & V information along with their subtotals in the next line of the file and create a new file, The dealer position along with corresponding totals may change everyday to any position above or below in the file, please help Thanks (2 Replies)
Discussion started by: Ariean
2 Replies

5. Shell Programming and Scripting

output - tab formatted - awk

Dear All, Good Day. I would like to hear your suggestions for the following problem: I have a file with 5 columns with some numbers in 16 lines as shown below. Input file: Col 1 Col 2 Col 3 Col 4 Col 5 12 220 2 121 20 234 30 22 9... (3 Replies)
Discussion started by: Fredrick
3 Replies

6. Shell Programming and Scripting

delete to end of formatted warnings using sed or cut...

hi, i've searched the forums' entries and have tried some of the examples -- to no avial -- this is my first post -- thanks in advance for your help... As part of an installation program -- i'm receiving two(2) extraneous "libcxb WARNING!" statements -- i want to use sed to eliminate the... (12 Replies)
Discussion started by: rickkar
12 Replies

7. Shell Programming and Scripting

Formatted Output

Hi I have the following lines in a file SWPRC000001NOT STATED 1344 SWPRC000001NOT STATED 1362 SWPRC000001NOT STATED 1418 SWPRC000001NOT STATED 1436 SWPRC000001NOT STATED ... (6 Replies)
Discussion started by: dhanamurthy
6 Replies

8. Shell Programming and Scripting

Formatted output - awk

Hi I have the following records in a file SABN YOURTUBE 000514 7256 SACN XYOUDSDF 000514 7356 SADN KEHLHRSER 000514 7656 SAEN YOURTUBE 000514 7156 SAFN YOURTUBE 000514 7056 I need to put this in the format like this printf '%s %-50s %6s %-6s\n' I am not going to read individual... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

9. Shell Programming and Scripting

formatted output with commas

var=12345 echo $var >>>12345 printf "%8.1f \n" $var >>> 12345.0 How to get this as 12,345? I suppose I could break into sections by dividing by 1000 or 1000000. But, is the a trick to this? (4 Replies)
Discussion started by: joeyg
4 Replies

10. Shell Programming and Scripting

Formatted output in KSH

Hi, Is there some way to get formatted output in ksh? Something like a properly alligned tabular format. I tried adding '\t' to echo statements, but it doesn't come properly alligned 'hello' A simple Hello 'helloworld' A helloworld statement I need the second coloumn to... (1 Reply)
Discussion started by: psynaps3
1 Replies
Login or Register to Ask a Question

Featured Tech Videos