Print in a specific position


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print in a specific position
# 1  
Old 02-06-2012
Print in a specific position

HI
My input is

12345678901234567890123456789012345678
pay 234 56789.23 7788934.5 2456
calcul 123 456 678 98
i want to print the line starting with "pay" as $2 should commence from 7 irresptive of its length and $3 to start from 14 and $4 to start from 24 and $5 from 36.
line starting with calcul is untouched and should print as it is($0)

Any way out fot these.

thnks nd regrds
# 2  
Old 02-07-2012
Code:
$ perl -ane '(/^pay/) && printf ("%-6s%-7s%-10s%-12s%d", $F[0], $F[1], $F[2], $F[3], $F[4])' inputfile
pay   234    56789.23  7788934.5   2456

# 3  
Old 02-07-2012
its not working for me....what about the line with calcul,its not getting printed out!!!
anything with awk or sed please

---------- Post updated at 11:21 PM ---------- Previous update was at 11:16 PM ----------

i have thousands of line starting with "pay"
pay 234 56789.23 7788934.5 2456
calcul 123 456 678 98
pay 234 56789.23 7788934.5 2456
calcul 123 456 678 98
etc etc

and the script prints all in a single line actually...
any way out plz..thanks a lot
# 4  
Old 02-07-2012
Code:
perl -lane '(/^pay/)?printf ("%-6s%-7s%-10s%-12s%d\n", $F[0], $F[1], $F[2], $F[3], $F[4]):print' inputfile

# 5  
Old 02-07-2012
Hi Balajesuri,
thanks alot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Need command or script to print all lines from 2nd position to last but one position

hi guys, i want command or script to display the content of file from 2nd position to last but one position of a file abcdefghdasdasdsd 123,345,678,345,323 434,656,656,656,656 678,878,878,989,545 4565656667,65656 i want to display the same above file without first and... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

substitute a string on a specific position for specific lines

I woud like to substitue a string on a specific position for specific lines I've got a file and I would like to change a specific string from "TOCHANGE" to "ABCABCAB" For every line (except 1,2, 3 and the last one) , I need to check between the 9th and the 16th digits. For the 3rd line, I... (7 Replies)
Discussion started by: BSF
7 Replies

4. Shell Programming and Scripting

Search in specific position and print the whole line

I have two files abc.dat and sant.dat (Big file 60k rows) for every line's 1,4 of abc.dat need to seach if this is present on 28,4 of sant.dat every line. if its present the output needs to go to bde.dat Example: contents abc.dat aaaa bbbb cccc dddd contents sant.dat this is... (4 Replies)
Discussion started by: ssantoshss
4 Replies

5. Shell Programming and Scripting

Using sed to replace specific character and specific position

I am trying to use sed to replace specific characters at a specific position in the file with a different value... can this be done? Example: File: A0199999123 A0199999124 A0199999125 Need to replace 99999 in positions 3-7 with 88888. Any help is appreciated. (5 Replies)
Discussion started by: programmer22
5 Replies

6. Shell Programming and Scripting

Print lines with specific character at nth position in a file

I need to print lines with character S at nth position in a file...can someone pl help me with appropriate awk command for this (1 Reply)
Discussion started by: manaswinig
1 Replies

7. Shell Programming and Scripting

Print lines with specific character at nth position in a file

I need to print lines with character S at nth position in a file...can someone pl help me with appropriate awk command for this (2 Replies)
Discussion started by: manaswinig
2 Replies

8. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

9. Shell Programming and Scripting

How to print at a specific position of the display

Hi, How can I write a string in a specific position of the screen in a bourne shell? Regards, Elio (1 Reply)
Discussion started by: efernandes
1 Replies

10. Shell Programming and Scripting

Print lines with search string at specific position

Hi Folks, I have a file with all fields defined by byte position, but any field can be empty so I cannot print lines based on a search of specific columns. I need to print all lines of this file where the string of two characters at byte position 100-101 contains the number 27. Any ideas? ... (4 Replies)
Discussion started by: HealthyGuy
4 Replies
Login or Register to Ask a Question