Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
We are doing a Linux workshop for college, and I was looking for a way to demonstrate using awk, sed and cut in the same pipe. I ve been thinking of using them in a apache server context (apache logs file), but is there other contexts I can use awk and sed and cut in?
here is one use
assume we want to convert all some vowels to uppercase sort some words based on the length
given file
$ cat file
apple
pear
banana
$ sed 'y/aeiu/AEIU/' file | awk '{print length "\t" $0}' | sort -n | cut -f2
pEAr
ApplE
bAnAnA
sed can be replaced with tr as well.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I'm trying to display only the users' name from a downloaded file in Linux named users.csv. The format of file is users; /home/directory.
I tried the following:
cut -d: -f1 users.csv
And also
awk -F: '{printf $1}' users.csv
None of them works. After enter home directory shows too.
Since the field delimiter is ";" and not ":", you need to specify it in the commands and so:
cut -d\; -f1 users.csv
awk -F\; '{ print $1 }' users.csv
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I got the following line
2020-10-17 14:55:39,586 INFO [http-bio-exec-60] [] [D88E13F571A51598613FAA078A215326.server.host.com.:9991] [some.package.Class] TEST_STRING - RSI: 506B48ECADC4BE0CEBF7C7D33D036B67.server.host.com.:9991
I do grep "D88E13F571A51598613FAA078A215326" and got the line above. Is there a way to run a command after grep to check if D88E13F571A51598613FAA078A215326 and 506B48ECADC4BE0CEBF7C7D33D036B67 are equal?
Thanks.
This will work if you already know the first pattern:
PATTERN=D88E13F571A51598613FAA078A215326
grep "\[$PATTERN.*RSI: $PATTERN" input_file
I got the following line, that's not a good way to start here:
Your line contains quite some information, and as mentioned in the comments, you might parse it using Perl or awk or any other tool, but I would advise otherwise: how do you get this line (I guess it's an output of some process)? You might ask the author of that other process to alter the output in such a way that it's easier for you do parse it and do the comparison you're aiming for.
Pipe grep output into this Perl one-liner, which splits the line on non-word characters and prints it if fields 13 and 23 are identical as strings:
echo '2020-10-17 14:55:39,586 INFO [http-bio-exec-60] [] [D88E13F571A51598613FAA078A215326.server.host.com.:9991] [some.package.Class] TEST_STRING - RSI: 506B48ECADC4BE0CEBF7C7D33D036B67.server.host.com.:9991' | \
grep 'D88E13F571A51598613FAA078A215326' | \
perl -F'/\W+/' -lane 'print if $F[12] eq $F[22];'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I have a csv with 100 rows, i want shuffle all rows skipping the first 2, but i dont find how exclude the first 2 lines
Now it is like this:
shuf words.txt > shuffled_words.txt
Can somebody help me?
The shell lets you easily combine text and file manipulation commands using pipes.
sed 1,2d words.txt | shuf >shuffled_words.txt
There are many ways to skin this cat; tail -n +2 words.txt or awk 'FNR>2' words.txt are also common and idiomatic ways to remove the first two lines.
Or something like this:
( head -n 2 words.txt ; tail -n +2 words.txt|shuf ) > shuffled_words.txt
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
What command would you give to list all English-language words that are exactly 5 characters long and that begin with an upper or lower-case vowel (‘a’, ‘e’, ‘i’, ‘o’, ‘u’, or ‘y’), have a lower-case ‘t’ in the middle position, and end with a lower-case ‘s’?
The remaining letters could be any character that occurs in English words, including but not limited to upper and lower-case alphabetics, numbers, hyphens, etc.
You had it almost!
grep ^[AaEeIiOoUuYy].t.s$ /usr/share/dict/words
Since I prefer complex pipelines to complex regular expressions, here's my take:
cat /usr/share/dict/words \
| grep -E -x ".{5}" \
| grep '^[aeiouyAEIOUY]' \
| grep '..t.s'
(Useless use of cat added for readability).
On my Ubuntu it produces this output:
Art's
Estes
Oates
Oct's
Yates
act's
altos
ant's
antes
antis
art's
autos
iotas
oat's
oaths
out's
(You can replace .{5} with \w{5} or with [a-zA-Z0-9-]{5} or whatever you like).
I've actually written a similar script to chea.. I mean, help me with crosswords.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I need help with comparison of two files and get the positions in third file, both files will have the same fields but the order will be unsorted in 2nd file, third file will give the line number where the data is found.
eg. file1.txt
A
B
C
D
file2.txt
B
D
A
C
outputfileposition.txt
3
1
4
2
Any help appreciated, thanks in advance
In awk
awk 'FNR==NR{a[$0]=FNR;next}{print a[$0] > "outputfileposition.txt"}' file{2,1}.txt
This will do the trick :
while read line
do
grep -n $line file2.txt | grep -o ^[0-9]* >> outputfileposition.txt
done < file1.txt