Search Results

Search: Posts Made By: Christoph Spohr
2,471
Posted By Christoph Spohr
No, in traditional awk you can't do that, as awk...
No, in traditional awk you can't do that, as awk doesn't support back references. If you use Gnu awk (gawk), you could use the gensub()-function, which supports back references. If you don't have...
3,853
Posted By Christoph Spohr
Simply because it didn't work that way, so i...
Simply because it didn't work that way, so i tried something else. You can't use $2..$4 to create the hash table value as your input file contains different amounts of spaces. You would get different...
21,086
Posted By Christoph Spohr
Hi, try: awk -F, 'BEGIN{print "Category...
Hi,

try:

awk -F, 'BEGIN{print "Category \t Counts"}$2 ~ /^KKK/{a[$2]+=1}END{for(i in a){print i" =\t"a[i]}}' file

HTH Chris
3,853
Posted By Christoph Spohr
O.k. awk -F, # make "," the new field...
O.k.

awk -F, # make "," the new field delimiter
'{gsub(/ */,"",$0); # the format of your data is not consistent
# -> delete all blanks
split($0,t,","); # split the...
3,853
Posted By Christoph Spohr
Hi, try awk -F, '{gsub(/...
Hi,

try

awk -F, '{gsub(/ */,"",$0);split($0,t,",");a[t[2]", "t[3]", "t[4]]+=$1}END{for (i in a) print a[i],i}' file1 file2 file3

Output:
24 a, b, c
7 d, e, f
9 b, c, a


HTH Chris
1,299
Posted By Christoph Spohr
Are you using vi oder vim? In vim you can use the...
Are you using vi oder vim? In vim you can use the up and down arrows to browse through the command history. Or you can type in normal mode "q:" to edit the command history.

HTH Chris
2,030
Posted By Christoph Spohr
Not pretty, but it works. It uses NF to check if...
Not pretty, but it works. It uses NF to check if the number
of fields is greater than 1.


awk -F, 'NF > 1 && NR==FNR{for (i=1;i<=NF;i++)
{t=length($i)+2;(t>a[i])?a[i]=t:a[i]=a[i]}}
...
2,018
Posted By Christoph Spohr
For me it does work. So what exactly doesn't work...
For me it does work. So what exactly doesn't work for you.
2,030
Posted By Christoph Spohr
Hi, for a file like: ...
Hi,

for a file like:

Year,Make,Model,Extras
1997,Ford,E350,variables
2000,Mercury,Cougar,examples


This command:
awk -F, 'NR==FNR{for (i=1;i<=NF;i++)
...
2,018
Posted By Christoph Spohr
Yupp, try this: awk '{getline s < "file2";...
Yupp,

try this:
awk '{getline s < "file2"; split(s,a,"[ \t]+");print $0 FS a[9]}' file1
2,018
Posted By Christoph Spohr
Hi, or with awk: awk...
Hi,

or with awk:

awk 'NR==FNR{a[++i]=$9}NR!=FNR{t=$1;sub(/B_/,"",t);print $0 FS a[t]}' file2 file1

Output:
B_1 gihgjfhdj| hgfkddlldjljldjlddl be_10
B_2 gihgjddshjgfhs|...
3,197
Posted By Christoph Spohr
Hi, variable substitution via...
Hi,

variable substitution via ${var//exp1/exp2} is a feature of bash
or zsh, not the sh. Consequently your code will not work with
!#/usr/bin/sh. Change it to bash.

HTH Chris
2,866
Posted By Christoph Spohr
Hi, if you have three files file1, file2 and...
Hi,

if you have three files file1, file2 and file3 with content like:

file1:
"anon@yahoo.com","anon",,,,,,,,,,,,01/16/08 08:05 PM,,"WIQC PDX"
"berti@yahoo.com","anon",,,,,,,,,,,,01/16/08...
8,147
Posted By Christoph Spohr
Hi, i don't understand your awk-command, but...
Hi,

i don't understand your awk-command, but suppose your file is:


Reason: Not Active (This is a string1)
AAAA
BBBB
CCCC
DDDD


Reason: Not Eligible
EEEE
FFFF


And your desired...
4,892
Posted By Christoph Spohr
Ok, try: sed -n...
Ok, try:

sed -n "/\sstring\/one\s/,/Finished/{p}" file

Output:
This is string/one today
string/one_is_here
string/one_is_there
Finished with the list


HTH Chris
4,892
Posted By Christoph Spohr
Please give examples of your desired input and...
Please give examples of your desired input and output.

Chris
8,464
Posted By Christoph Spohr
Or with grep: grep -o "SQLSTATE=[0-9][0-9]*"...
Or with grep:

grep -o "SQLSTATE=[0-9][0-9]*" error.log

HTH Chris
4,403
Posted By Christoph Spohr
Hi, if your string ...
Hi,

if your string

[rquote=123456&tid=1234567&author=othernick] This is message text that is being quoted

is saved in a file called "file". This:

sed...
4,494
Posted By Christoph Spohr
Hi, try: awk...
Hi,

try:

awk '/Folder>/{s=$0;t=getline;if ($0 ~ /Points/){f=0} else {if (t) print s;f=1}}f' file

Output:
<Folder>
<name>Waypoints</name>
# SOME ESSENTIAL STUFF
# SOME ESSENTIAL...
14,851
Posted By Christoph Spohr
Please give examples of the cases where the...
Please give examples of the cases where the script failes, so i can test the script.
14,851
Posted By Christoph Spohr
Hi, try: awk '{if ($4 > a[$1" "$2"...
Hi,

try:

awk '{if ($4 > a[$1" "$2" "$3])a[$1" "$2" "$3]=$4}END{for (i in a) print i, a[i]}' file

Output:

3333 4444 BBBB 0.7
1111 2222 AAAA 0.9


HTH Chris
2,024
Posted By Christoph Spohr
Hi, try: awk 'f==0 &&...
Hi,

try:

awk 'f==0 && /^>/{sub(/>[^>]*$/,"",$0);print $0;f=1}!/.*>.*/{print $0;f=0}' file

It gives me:

>answer is the predicted other than
CGAHHAWWASSASS
SASAWEDSASSDDD
SSDDDEDEUJUYYS...
18,194
Posted By Christoph Spohr
Hi, try: awk '/xml/{c++}{print > "file"...
Hi,

try:

awk '/xml/{c++}{print > "file" c ".xml"}' file

HTH

Chris
1,002
Posted By Christoph Spohr
Hi, keep it simple. echo...
Hi,

keep it simple.

echo "7.5.aa.sss.dddd_ROLD" | sed -n 's/_[^_]*$//p'

Does the trick for me.

Output:
7.5.aa.sss.dddd


HTH Chris
2,372
Posted By Christoph Spohr
Hi, try: awk 'NR==FNR{a[$1$2]}{if ($3$5...
Hi,

try:

awk 'NR==FNR{a[$1$2]}{if ($3$5 in a) print $0}' file1 file2

gives me:
CA USA 204.11.23.1 200 fastmovie.mp4

HTH Chris
Showing results 1 to 25 of 237

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