hello,
I want to replace awk with a perl one liner in unix.
i use in awk REGEX and FS ( field separator) because
awk syntaxes in different unix os versions have not the same behaviour.
i have a file named "file" and want search the exact value (example: search_value) of the first entry (FS="#" ). but there can be some characters at the beginning (REGEXP)
UNIX: AWK in a KSH script:
this works not at whole unix os versions, so i have develope a perl one liner ( i have mininamal perl know how,i use examples of the net ):
UNIX: PERL in a KSH script :
is it ok ? problem is to put the unix shell variable to perl .
regards
Moderator's Comments:
Please use next time code tags for your code and data
Ok, but be aware: perl is NOT POSIX so it is not guaranteed to be on a given unix box.
Next, there are different awk versions on some machines - KSH by itself does not enforce a particular version of awk. So simply using
does not guarantee anything about awk.
Systems can have aliases: awk for GNU gawk, for example. Solaris has an ancient version of awk: /usr/bin/awk plus others: /usr/bin/nawk (what you want to use)
Circumventing the portability problem by assuming perl is there is not necessarily a good option.
My point: you may be wasting your time if this has to be freely portable.
This User Gave Thanks to jim mcnamara For This Post:
Circumventing the portability problem by assuming perl is there is not necessarily a good option.
My point: you may be wasting your time if this has to be freely portable.
hmm, what should it do, when i want to use a shell script at different os versions (HP-UX, Linux (SuSe / RedHat ).
like :
i thought "perl" was a good option.
regards
Last edited by Franklin52; 02-04-2012 at 02:20 PM..
Reason: Please use code tags for data and code samples, thank you
Improve your awk script, I'd say... Surely it's possible to make it portable, if it isn't already. The only thing I see which might not be completely portable is the -v. In what way does it not work, and on what particular platform?
What does (+search_string) mean, anyway?
Try
Last edited by Corona688; 02-03-2012 at 05:04 PM..
Ok, but be aware: perl is NOT POSIX so it is not guaranteed to be on a given unix box.
this is new for me but for me issue : the behaviour of REGEXP is the same at all os versions? right ? i have to test it !
---------- Post updated at 03:20 PM ---------- Previous update was at 03:03 PM ----------
Quote:
Originally Posted by Corona688
Improve your awk script, I'd say... Surely it's possible to make it portable, if it isn't already. The only thing I see which might not be completely portable is the -v. In what way does it not work, and on what particular platform?
it is here a example, some i want to search with strings that includes "/" ( like filesystems) . so i use -v . but when i have it in a "awk" variable, it isn't easy to use REGEXP
Try
(+search_string) : i want to match zero or more occurrences before the "search_string" like the REGEXP of "grep" .*
i search with example above , but not including in search "+"
file:
;;search_value1#field1#field2#junk#junk#junk#junk
;;search_value2#field1#field2#junk#junk#junk#junk
+++++++++++++++++++++++++++++++++++++++++++++
search_string="search_value1"
i want to search only "search_value1"
+++++++++++++++++++++++++++++++++++++++++++++
search_string="search_value1"
i want to search all with "search_value1*" (example: search_value1,search_value11,search_value111, not search_value121)
Trying to find and replace one string with another string in a file
#!/usr/bin/perl
$csd_table_path = "/file.ntab";
$find_str = '--bundle_type=021';
$repl_str = '--bundle_type=021 --target=/dev/disk1s2';
if( system("/usr/bin/perl -p -i -e 's/$find_str/$repl_str/' $csd_table_path")... (2 Replies)
Hi,
I am a newbie to awk. Here is my problem. Looking for an awk 1-liner to solve it:
My Computing Environment:
- Solaris10
- I prefer to use csh or sh shells
1. Lets say my input file is File1.dat (delimter = | ) and looks as follows:
(File1.dat)
... (1 Reply)
Not quite a unix question but problem in a perl command. Taking a chance if someone knows about the error
cat 1
a b c d
perl -p -e 's/a/b/g' 1
b b c d
What is the problem here??
perl -p -i -e 's/a/b/g' 1
Can't remove 1: Text file busy, skipping file. (2 Replies)
Hello all
According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values
example, running this script/command like
./script.sh xxapp
I would expect as output: 102 116 112
./script.sh xxapp2... (2 Replies)
can someone help me translate the following command, from:
/usr/bin/awk "/^$TOFDAYM $TOFDAYD /,0" $LOGFILE
to something like
perl -e .....
basically, i want to use perl to do awk functions within a shell script. i want to do the above awk, using perl.
any suggestions? (9 Replies)
Hi, I'm writing a ksh script and trying to use an awk / sed / or perl one-liner to remove the last 4 characters of a line in a file if it begins with a period.
Here is the contents of the file... the column in which I want to remove the last 4 characters is the last column. ($6 in awk). I've... (10 Replies)
Hi!
I have a difficult problem, to step up a unknown version number in a text file, and save the file. It would be great to run script.sh and the version gets increased.
Example the content of the textfile.txt
hello
version = x
bye
This include three steps
1. First find the char after... (2 Replies)
Thanks for giving your time and effort to answer questions and helping newbies like me understand awk.
I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk.
Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Hi
I am trying to search and replace a multi line pattern in a php file using awk.
The pattern starts with
<div id="navbar">
and ends with
</div>
and spans over an unknown number of lines.
I need the command to be a one liner.
I use the "record separator" like this :
awk -v... (8 Replies)