![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep for a particular pattern and remove few lines above top and bottom of the patter | fed.linuxgossip | Shell Programming and Scripting | 17 | 07-25-2008 09:29 AM |
| grep required pattern and next 2 or 3 lines | cvvsnm | UNIX for Dummies Questions & Answers | 3 | 02-01-2008 05:20 AM |
| grep to show lines only after pattern | wannalearn | Shell Programming and Scripting | 5 | 10-09-2007 03:44 AM |
| How to select lines in unix matches a pattern at a particular position | cs_banda | UNIX for Dummies Questions & Answers | 2 | 10-06-2006 04:28 PM |
| grep - to exclude lines beginning with pattern | frustrated1 | Shell Programming and Scripting | 2 | 08-29-2005 08:18 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to awk/sed/grep lines which contains a pattern at a given position
Dear friends
I am new to linux and was trying to split some files userwise in our linux server. I have a data file of 156 continuous columns named ecscr final. I want the script to redirect all the lines containing a pattern of 7 digits to separate files. I was using grep to do that, as below. I have written all available patterns to a file named usercode. while read alpha do cat ecscrfinal | grep -e $alpha >> mkoff.$alpha echo "Generating markoff data for $alpha" done < /home/ftp/ecs/usercode But I need only those lines which have the pattern occuring at 3rd column or 81st column to go to that file. In the above case if the pattern is found any wher in the line, it is redirected to that file which gives me a wrong result. How sed/awk/grep can be used to match a pattern occuring only at a specified field.....? The pattern should be matched only if it is occuring in 3rd position or 81st postition. Please help me.....i am running against a deadline......... |
|
||||
|
i tried like this
while read alpha do awk 'substr($0,3,7)<"$alpha"||substr($0,81,7)<"$alpha"'<ecscrfinal >> mkoff.$alpha awk 'substr($0,3,7)<"$alpha"||substr($0,81,7)<"$alpha"' <ecsdrfinal >> mkoff.$alpha done < /home/ftp/ecs/usercode which yielded no results then like this, $alph without quotes; while read alpha do awk 'substr($0,3,7)<$alpha||substr($0,81,7)<$alpha'<ecscrfinal >> mkoff.$alpha awk 'substr($0,3,7)<$alpha||substr($0,81,7)<$alpha' <ecsdrfinal >> mkoff.$alpha done < /home/ftp/ecs/usercode In this case the entire file is copied to all the userwise split files What I am doing wrong..... Cant I do substitution inside awk...?? |
![]() |
| Bookmarks |
| Tags |
| awk distinct column values, grep, sed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|