|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Fixed width file search based on position value
Hi, I am unable to find the right option to extract the data in the fixed width file. Code:
sample data abcd1234xgyhsyshijfkfk hujk9876 io xgla loki8787eljuwoejroiweo dkfj9098 dja Search based on position 8-9="xg" and print the entire row output abcd1234xgyhsyshijfkfk Thanks onesuri |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
$ awk ' substr($0,9,2) == "xg" ' file abcd1234xgyhsyshijfkfk |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
The position of "xg" is 9-10 despite the phrasing in the spec. Try Code:
$ grep -E "^.{8}xg" file
abcd1234xgyhsyshijfkfkor Code:
$ sed -En "/^.{8}xg/p" file
abcd1234xgyhsyshijfkfk |
|
#5
|
|||
|
|||
|
Dear ctsgnb,
What a fantastic and concise coding technique. I've fought with this for years, often cobbling some terrible script round it. Wonderful. Robin |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to split a fixed width text file into several ones based on a column value? | bhanja_trinanja | Shell Programming and Scripting | 14 | 12-28-2010 02:15 PM |
| Remove duplicates based on a column in fixed width file | Qwerty123 | UNIX for Dummies Questions & Answers | 1 | 07-15-2010 06:37 AM |
| row to column and position data in to fixed column width | baluchen | Shell Programming and Scripting | 4 | 03-15-2010 06:46 AM |
| Append line based on fixed position | ashikin_8119 | Shell Programming and Scripting | 2 | 03-19-2008 04:09 AM |
|
|