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.
Awk, Nawk and GNU Awk Cheat Sheet - good coders code, great reuse
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)
file:
;;search_value#field1#field2#junk#junk#junk#junk
UNIX: AWK in a KSH script:
search_string="search_value"
awk -v search_string="${search_string}" -F# '$1 ~ (+search_string) { print $1,$2,$3,$4 }' file
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 :
search_string="search_value" \
perl -l -a -n -F"#" -e 'print $F[1] if ($F[0] =~ /^\S+$ENV{"search_string"}$/ ) ' file
is it ok ? problem is to put the unix shell variable to perl .
regards