Search Results

Search: Posts Made By: khaled79
3,320
Posted By CarloM
The double square brackets are important - the...
The double square brackets are important - the character class [:alpha:] replaces a-zA-Z, you still need the outer brackets to denote a bracket expression.
$ grep -Ewo "[[:alpha:]]" all.txt | sort |...
2,553
Posted By Don Cragun
Of course. Change the last line of Yoda's script...
Of course. Change the last line of Yoda's script from:
' fileto:' file | sort -k8,8nr -k10,10nr
2,553
Posted By Don Cragun
As I said before, add it to the last line of...
As I said before, add it to the last line of Yoda's script; so change the last line of his awk script from:
' fileto:
' file | sort -k10,10nr
2,553
Posted By Don Cragun
Add to the end of the last line of Yoda's script:...
Add to the end of the last line of Yoda's script:
| sort -k10,10nr
Let me know if you'd like to make the context or character value fields secondary or tertiary sort keys (ascending or descending).
2,553
Posted By Yoda
Ok, I assumed you want to print previous record...
Ok, I assumed you want to print previous record each time you encounter record: 200/202/203

Here is a modified awk code:
awk '
BEGIN {
A["200"]
A["202"]...
2,553
Posted By Yoda
Based on some assumptions: awk ' ...
Based on some assumptions:
awk '
BEGIN {
A["200"]
A["202"]
A["203"]
}
$0 in A {
print "The context is "...
2,553
Posted By Yoda
BEGIN and END are special patterns usually used...
BEGIN and END are special patterns usually used for supplying startup and cleanup actions for awk programs.

BEGIN rule is executed once only, before the first input record is read.

END rule is...
2,553
Posted By Yoda
You could use the awk END block to print the...
You could use the awk END block to print the counter in the end:
awk -v S="$SEQ" '
$0 ~ S {
N++
}
END {
print N
}
'
967
Posted By Yoda
Yes, this will not work for large files because...
Yes, this will not work for large files because your code is trying to load all records from your input file to an Indexed Array!

Instead you should follow the approach used in previous code. In...
4,600
Posted By Yoda
I have previously posted similar codes which can...
I have previously posted similar codes which can be slightly modified to get your desired output.

So show us what you have tried so far, share your thoughts and efforts for approaching this...
4,600
Posted By Yoda
I'm sorry. I misread your requirement. I thought...
I'm sorry. I misread your requirement. I thought you want to print records in the order that you have them in your input file.

If you have gawk then you can use below code to print in descending...
4,600
Posted By Yoda
You can code something like: SEQ=200 awk -v...
You can code something like:
SEQ=200
awk -v S="$SEQ" '
{
A[++c] = $1
}
END {
for ( i = 1; i <= c; i++ )
{
...
4,600
Posted By Yoda
Yes you can. For implementing this change use...
Yes you can. For implementing this change use regular expression comparison operators ~ and !~ instead:
SEQ="45654|234567|57899"

awk -v S="$SEQ" '
$0 ~ S {
V = $0
...
4,600
Posted By Yoda
The first awk program that I posted loads all the...
The first awk program that I posted loads all the records in your file into an Indexed Array A[++c] = $1 and in the end it performs the required operation.

This caused the program to throw Cannot...
4,600
Posted By Yoda
How about this awk code? SEQ=45654 awk -v...
How about this awk code?
SEQ=45654

awk -v S="$SEQ" '
$0 == S {
V = $0
getline
if ( $0 == 199 )
{
...
4,600
Posted By rveri
Khaled79, Check this out: # v=45654;perl...
Khaled79,
Check this out:
# v=45654;perl -0777 -pe 's/$ENV{v}\n199\n225/$ENV{v}\n258/igs' file


235543
123
45654
258
578
45654
258
4,600
Posted By Yoda
I didn't quite understand what you mean by...
I didn't quite understand what you mean by variable sequence.

The program that I posted replaces 45654 199 225 to 45654 258

You just have to modify it as per your requirement.
4,600
Posted By Yoda
Here is a solution using awk: awk ' {...
Here is a solution using awk:
awk '
{
A[++c] = $1
}
END {
for ( i = 1; i <= c; i++ )
{
if (...
Showing results 1 to 18 of 18

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