- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: problem with awk script..
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
12-14-2006 02:21 AM
12-14-2006 02:21 AM
nawk -F"|" '
{ mo=substr($1,16,2)
day=substr($1,18,2)}
{print $15"|2007|"mo"|"day;} ' $1 > final
so basicly from my input file $1 with substring function I want to assign mo and day variable and have final file..
maybe it is not right pleace to assign mo and day in this part?? I am using KSH..
thanks..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 02:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 02:37 AM
12-14-2006 02:37 AM
Re: problem with awk script..
how about:
nawk -F"|" '{ mo=substr($0,16,2); day=substr($0,18,2)} {print $15"|2007|"mo"|"day;} ' $1 > final
May be helpful if you provided input and expected output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 02:52 AM
12-14-2006 02:52 AM
Re: problem with awk script..
if Peter's tip is ($0 is the complete line of input) not what you mean: Do you want to extract the day+month information from the filename you supply?
Then use, use
nawk -F"|" 'FNR==1 {mo=substr(FILENAME,16,2)
day=substr(FILENAME,18,2)}
{print $15"|2007|"mo"|"day;}' in1 in2 .. >final
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 03:06 AM
12-14-2006 03:06 AM
Re: problem with awk script..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 03:08 AM
12-14-2006 03:08 AM
Re: problem with awk script..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 03:20 AM
12-14-2006 03:20 AM
Re: problem with awk script..
now I have file1:
232323|2007|12|09
343434|2007|12|09
565656|2007|12|09
898989|2007|12|09
090909|2007|12|09
..
..
and file 2:
232323
343434
343433
343432
343431
..
..
My result that does not work OK with command grep -v -f file1 file2
and output should be:
232323|2007|12|09
343434|2007|12|09
thanks friends..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 03:30 AM
12-14-2006 03:30 AM
Re: problem with awk script..
# grep -f file2 file1
...you have the pattern file and the input file reversed and don't want the '-v'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 03:33 AM
12-14-2006 03:33 AM
Re: problem with awk script..
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
I got this error..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 04:07 AM
12-14-2006 04:07 AM
Re: problem with awk script..
# join -1 1 -2 1 -t'|' -o 1.1 1.2 1.3 1.4 file1 file2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 04:24 AM
12-14-2006 04:24 AM
Re: problem with awk script..
Based on the grep error message you provided, it doesn't appear you're using HP-UX (SunOS, perhaps?).
If that's the case, try:
$ /usr/xpg4/bin/grep -f file2 file1
or:
$ grep `cat file2` file1
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2006 06:22 PM
12-17-2006 06:22 PM
Re: problem with awk script..
grep 'cat file1' file2 does not work..
thanks friends..
cheers..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2006 02:13 AM
12-18-2006 02:13 AM
Re: problem with awk script..
file1:
232323|2007|12|09
343434|2007|12|09
565656|2007|12|09
898989|2007|12|09
090909|2007|12|09
..
..
file 2:
232323
343434
343433
343432
343431
..
..
# join -1 1 -2 1 -t'|' -o 1.1 1.2 1.3 1.4 file1 file2
The join(1) example above "glues" the two files (file1 and file2) together on the fields that are common to both...which is field 1 as shown by command line options -> "-1 1 -2 1".
The field separator is the pipe character -t'|' (needs to be escaped or quoted as it has special meaning to the shell, and the output should consist of all fields from the first file -> "-o 1.1 1.2 1.3 1.4".
imho...not sure why the grep command by JRF is not working for you. It works perfectly on my HP-UX box. Are you using HP-UX or some other variant?
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2006 03:13 AM
12-18-2006 03:13 AM
Re: problem with awk script..
of course JRF's solution works for Solaris as well - but you have to use the POSIX compliant binary:
/usr/xpg4/bin/grep -f file2 file1
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2006 06:00 PM
12-18-2006 06:00 PM
Re: problem with awk script..
yes /usr/xpg4/bin/grep -f file2 file1
works fine on my solaris..
thanks guys,
cheers,