- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: A filtering script help
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
06-10-2003 06:12 AM
06-10-2003 06:12 AM
I'm trying to split the attached file in several files, the split criteria must be by third number of IP address. I was tried using grep command, but dots are complicating this filter. Please consider that the file in real life doesn't contain only addresses, it doesn't begin with them and has more information inside. But is enough for the filtering example that I need!
Regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2003 06:29 AM
06-10-2003 06:29 AM
Re: A filtering script help
With this script, you will get 1 file (file.X) for each X (third field of IP address) :
#!/usr/bin/sh
IFS=".
"
cat b | while read LINE
do
set -- $LINE
echo $LINE >> file.$3
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2003 12:43 PM
06-10-2003 12:43 PM
Re: A filtering script help
Not sure I am reading this correctly but to obtain separate files for every three lines of your list of ip address (and other date -
#!/bin/ksh
grep -n '154.' your_file > lined_file
cut -d: -f1 lined_file > line_numbers
tail -1 line_numbers | read last_line
cat line_numbers | wc -l | read end
i=0
for x in `cat line_numbers`
do
echo $x | read var
value[i]=$var
let i="$i+1"
done
i=0
let end="$end-3"
fnum=0
while [ $i -lt $end ]
do
let a="${value[$i]}"
let i="$i+3"
let b="${value[$i]}-1"
let fnum="$fnum+1"
sed -n "$a","$b"p your_file > out_file.$fnum
done
let fnum="$fnum+1"
let b="$b+1"
sed -n "$b","$last_line"p your_file > out_file.$fnum
rm lined_file
rm line_numbers
Even if the number of lines in the file is not divisable by three all files will contain three unique entries. The last file will contain 1-3 lines dependent upon what was left.
Best of luck.
Regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2003 01:27 PM
06-10-2003 01:27 PM
Re: A filtering script help
You may be able to modify this to fit your own needs.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2003 06:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 03:59 AM
06-11-2003 03:59 AM
Re: A filtering script help
Try this simple csh script.
fileno=1;
linenum=0;
cat "filename"| while read LINE
do
echo $LINE >> file$fileno;
linenum=`expr $linenum + 1`
if [ `expr $linenum % 3` = 0 ]
then
fileno=`expr $fileno + 1`
echo "Linenum: $linenum Fileno: $fileno\n"
fi
done
Regards
VJ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 03:59 AM
06-11-2003 03:59 AM
Re: A filtering script help
Try this simple csh script.
fileno=1;
linenum=0;
cat "filename"| while read LINE
do
echo $LINE >> file$fileno;
linenum=`expr $linenum + 1`
if [ `expr $linenum % 3` = 0 ]
then
fileno=`expr $fileno + 1`
echo "Linenum: $linenum Fileno: $fileno\n"
fi
done
Regards
VJ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 04:00 AM
06-11-2003 04:00 AM
Re: A filtering script help
Try this simple csh script.
fileno=1;
linenum=0;
cat "filename"| while read LINE
do
echo $LINE >> file$fileno;
linenum=`expr $linenum + 1`
if [ `expr $linenum % 3` = 0 ]
then
fileno=`expr $fileno + 1`
echo "Linenum: $linenum Fileno: $fileno\n"
fi
done
Regards
VJ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 06:33 AM
06-11-2003 06:33 AM
Re: A filtering script help
excuse for the lack of undrstanding your question.
a single line will take care of your issue, this is if I understnad it correctly.
cat
peace
donny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 03:29 PM
06-11-2003 03:29 PM
Re: A filtering script help
cut the columns where the IPs are expected, and assure not include garbage.
i think in two scripts to obtain a file for each net (third number)
cat filewithips | cut -c1-17 | grep -e"." | xargs -i scriptnet.sh {}
where scriptnet.sh has
net=`echo $1 | cut -f3 -d.`
echo $1 > net.$net
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2003 12:01 AM
06-12-2003 12:01 AM
Re: A filtering script help
If you like working with PERL, attached are two examples that sort a list of IPs to separate files by the third octet.