Sponsored Content
Top Forums Shell Programming and Scripting replace awk with a perl one liner (REGEXP and FS) Post 302597421 by bora99 on Friday 10th of February 2012 09:20:28 AM
Old 02-10-2012
Quote:
Originally Posted by jim mcnamara
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?
Code:
What does (+search_string) mean, anyway?

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
Code:
awk -F# '$1 ~ search_string { print $1,$2,$3,$4 }' search_string="${search_string}" file

(+search_string) : i want to match zero or more occurrences before the "search_string" like the REGEXP of "grep" .*

how i use REGEXP for awk for following examples :


+++++++++++++++++++++++++++++++++++++++++++++
easy:
awk -F# '$1 ~ search_string { print $1,$2,$3,$4 }' file:
search_string="search_value"

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"

file:
;;search_value1#field1#field2#junk#junk#junk#junk
;;search_value11#field1#field2#junk#junk#junk#junk

+++++++++++++++++++++++++++++++++++++++++++++
search_string="search_value1"
i want to search all with "search_value1*" (example: search_value1,search_value11,search_value111, not search_value121)

file:
;;search_value1#field1#field2#junk#junk#junk#junk
;;search_value11#field1#field2#junk#junk#junk#junk
;;search_value111#field1#field2#junk#junk#junk#junk
;;search_value121#field1#field2#junk#junk#junk#junk

regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk/perl one-liner assist

In a ~4GB file there are lines like, 13.13.4.3 Googe.com - Jan/23/2011:00:00:00 +0000 "URL Google HTTP/1.1" 45 56 208 - "http://www.gogle.com/webhp?hl=en&tab=nw#hl=en&source=hp&biw=1366&bih=667&q=hello&aq=f&aqi=&aql=&oq=&fp=c432485467934a89" ".Net; Fox" - 13.145.3.3 Goge.com -... (3 Replies)
Discussion started by: gameboy87
3 Replies

2. Shell Programming and Scripting

awk multiple-line search and replace one-liner

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)
Discussion started by: louisJ
8 Replies

3. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

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)
Discussion started by: verge
9 Replies

4. Shell Programming and Scripting

Advanced AWK Regexp substring to int & Replace

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)
Discussion started by: Beachboy72
2 Replies

5. Shell Programming and Scripting

Need an awk / sed / or perl one-liner to remove last 4 characters with non-unique pattern.

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)
Discussion started by: right_coaster
10 Replies

6. Shell Programming and Scripting

Replacing Awk with One-liner Perl

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)
Discussion started by: SkySmart
9 Replies

7. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

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)
Discussion started by: cabrao
2 Replies

8. UNIX for Dummies Questions & Answers

Perl one liner to replace text

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)
Discussion started by: analyst
2 Replies

9. UNIX for Dummies Questions & Answers

What awk 1-liner will replace value in 1stField of a delimited file with the value of '5' ?

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)
Discussion started by: andy b
1 Replies

10. Shell Programming and Scripting

find and Replace String in Perl - Regexp

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)
Discussion started by: cillmor
2 Replies
All times are GMT -4. The time now is 12:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy