- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to grep a formatted file for matching text exa...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2003 06:11 AM
05-16-2003 06:11 AM
In example below I just want to print out lines that match
the field which begins at posiotion 21 in each line e.g. 5398888500404
From below, from the three line sample, two lines would match....Hope you can understand what I need to do..?
010220030326030735065398888500404 01200012030102
010220030326030735065398888500505 20302302030230
010220030326030735065398888500404 23232232323233
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2003 06:21 AM
05-16-2003 06:21 AM
Re: How to grep a formatted file for matching text exact positions
while read line
do
var1=$(echo $line | cut 21-33)
if [ $var1 = 5398888500404 ]
then
echo $var1 >> file2
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2003 06:21 AM
05-16-2003 06:21 AM
Re: How to grep a formatted file for matching text exact positions
grep "^....................5398888500404" file
Kind of kludgy because you have to count out "." to the position you want.
You could use awk-
awk 'substr($0,21,13)=="5398888500404"{print $0}' file
You could use perl-
perl -n -e 'print $_ if substr($_,20,13) eq "5398888500404"'
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2003 06:22 AM
05-16-2003 06:22 AM
Re: How to grep a formatted file for matching text exact positions
cat file |
while read line
do
var1=$(echo $line | cut 21-33)
if [ $var1 = 5398888500404 ]
then
echo $line >> file2
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2003 06:29 AM
05-16-2003 06:29 AM
Solutiongrep '^.\{20,20\}pattern'
^ is the start of the line
. is any character
\{20,20\} means 20 repetitions of the previous regular expression, i.e. 20 any-characters
pattern is the real pattern to be grep(1)-ped.
I.e. for example for your example data and pattern:
$ cat message | grep '^.\{20,20\}5398888500404'
010220030326030735065398888500404 01200012030102
010220030326030735065398888500404 23232232323233
$