Search Results

Search: Posts Made By: dsid
1,992
Posted By MadeInGermany
Some awk do not have {n,m} in their ERE, but all...
Some awk do not have {n,m} in their ERE, but all have index():
awk '(/^0[67][MV]/ && index($0,"003529")==26) {c=6} (c && c--)' file
1,992
Posted By drl
Hi. Here are some alternatives for versions...
Hi.

Here are some alternatives for versions of grep that do not support options -A and -B:
Print lines above, below pattern-matched line (context, window); "only" string matching pattern

...
1,992
Posted By RudiC
Try also grep -A5 "^0[67][MV].\{22\}003529"...
Try also
grep -A5 "^0[67][MV].\{22\}003529" file

OR

awk '/^0[67][MV]......................003529/ {L = NR + 6} NR < L' file
15,802
Posted By MadeInGermany
I missed something: \1 is certainly a...
I missed something: \1 is certainly a backreference to the ( ) and should become $1 in perl, and needs to be separated from the following text
perl -i.Original -pe '/^4000/ and s/(.{136})...
15,802
Posted By Scrutinizer
Hi, What we forgot to mention in the other...
Hi,

What we forgot to mention in the other thread (https://www.unix.com/shell-programming-and-scripting/271787-search-replace-specific-positions-specific-lines.html) is that when you use 000...
15,802
Posted By MadeInGermany
You can easily port it to perl perl -i.Original...
You can easily port it to perl
perl -i.Original -pe '/^4000/ and s/(.{136}) 36|000/\1036/' file
1,278
Posted By RudiC
/.../ is a regular expression; c.f. man awk:...
/.../ is a regular expression; c.f. man awk: "Regular expressions are enclosed in slashes". A single / is pointless.
^ anchors the regex at begin-of-line (or string).
.* represents "any...
1,278
Posted By RudiC
How about id | awk '{gsub (/^.*=|\)/, "", $1);...
How about
id | awk '{gsub (/^.*=|\)/, "", $1); sub (/\(/, " ", $1); print $1}'
1000 userid
1,947
Posted By Scrutinizer
Hi, try: sed '/^4000/s/\(.\{136\}\).../\1036/'...
Hi, try:
sed '/^4000/s/\(.\{136\}\).../\1036/' file
or
sed -r '/^4000/s/(.{136}).../\1036/' file

You can use the -i in place option with sed on your system, but it is best to then also specify...
1,947
Posted By Scrutinizer
That is correct, a dot in regex means "any...
That is correct, a dot in regex means "any character" .



--

Hi RudiC, IMO that was not a specification, but rather a remark. It says: which will be '000', therefore I used '...' instead..
1,947
Posted By RudiC
If you compare the two sed scripts, the one with...
If you compare the two sed scripts, the one with the -r option is way simpler (not that many escapes needed).
The \1 ("back reference") substitutes the 1. paranthesized regex part with itself.
In...
4,238
Posted By RudiC
In fact, it's not a work around but one of the...
In fact, it's not a work around but one of the basic methods in data processing.
4,238
Posted By RudiC
A day has 24 hours; you want to assign a certain...
A day has 24 hours; you want to assign a certain value to each hour, a linear relationship that could be calculated has been rejected; so I put the desired values as defined by YOU into a 24 element...
4,238
Posted By RudiC
Try awk -F, 'BEGIN {split...
Try
awk -F, 'BEGIN {split ("3,3,3,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,2,2,2,0", B); B[0] = 3} {print $1, "CUT " B[$2+0]}' file



EDIT: or, even better:

awk -F, 'BEGIN {split...
4,238
Posted By Corona688
Lots of code here is less than ideal for purposes...
Lots of code here is less than ideal for purposes of brevity and using the tools available, but doing it in sed is just so pointlessly difficult, vs it being so laughably easy in awk, that I really...
4,238
Posted By Corona688
sed doesn't really have comparisons, variables,...
sed doesn't really have comparisons, variables, expressions, or even numbers... It doesn't have anything you're asking it to do. You'd have to tell sed how to comprehend numbers in the form of many...
1,910
Posted By vgersh99
loose the double quotes - your...
loose the double quotes - your cmptl_extr_list_file contains the file globbing that needs to be expanded by shell :

/bin/grep "$flnm_80BYTE" ${cmptl_extr_list_file}
9,809
Posted By Scrutinizer
1. an 2.print for loops over all the matches by...
1. an 2.print for loops over all the matches by /\b(\d{23})\b/g

/\[(\d+)\]/ and print $1 means if there is a match then print the first match
3.globally per line. And since this is done for...
9,809
Posted By Scrutinizer
Also with perl you could add boundary operators :...
Also with perl you could add boundary operators :
perl -nle '/\b(\d{23})\b/ and print $1'

Note that this code differs from other approaches, in the sense that it only prints the first occurrence...
9,809
Posted By MadeInGermany
To prevent consumption of leading digits you can...
To prevent consumption of leading digits you can exclude them from the leading pattern
sed -n 's/[^0-9]*\([0-9]\{23\}\).*/\1/p'
9,809
Posted By vgersh99
this is because the leading .* is greedy - it...
this is because the leading .* is greedy - it "chows" as many characters as possible (including numbers) and then "chows up" 23 numbers and then everything else till the end of the record/line...
9,809
Posted By Scrutinizer
Hi dsid The single quotes are better at...
Hi dsid

The single quotes are better at protecting the regular expression from the shell, than double quotes, so that is why I prefer to use them. When you read that they remove any meaning from...
9,809
Posted By vgersh99
-F defines field delimiters. In this particular...
-F defines field delimiters. In this particular case the field delimiters are [] as the 23-digit long string is surrounded by [].
We subtract 1 from $NF because the LAST field is following the ]....
9,809
Posted By andy391791
Sed alternative sed -n...
Sed alternative

sed -n 's/.*\[\([0-9]\{23\}\)\].*/\1/p' filename
9,809
Posted By vgersh99
echo 'Original presentment record for ARN ...
echo 'Original presentment record for ARN [24013935350549886999873] not found' | awk -F'[][]' '/^Original presentment/ {print $(NF-1)}'
Showing results 1 to 25 of 31

 
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy