Awk extract fields with multiple seperator [on hold]Printing fields using awkAwk with multiple delimitersExtract multiple lines with secondary keyword searchExtract 2 fields from 2 different linesawk command with multiple commandsMultiple `awk` statements with pipes `|` ?awk to match and cut out fields with alternating delimiterawk, awk with variables, filegrep comma separated-fields with multiple conditionsTrouble pasting specific fields using awk
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
High voltage LED indicator 40-1000 VDC without additional power supply
Why is Minecraft giving an OpenGL error?
Find the result of this dual key cipher
Has there ever been an airliner design involving reducing generator load by installing solar panels?
How do I gain back my faith in my PhD degree?
How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?
NMaximize is not converging to a solution
Arrow those variables!
What are these boxed doors outside store fronts in New York?
What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)
"You are your self first supporter", a more proper way to say it
Is it possible to run Internet Explorer on OS X El Capitan?
Modeling an IP Address
Does an object always see its latest internal state irrespective of thread?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Is it unprofessional to ask if a job posting on GlassDoor is real?
What would happen to a modern skyscraper if it rains micro blackholes?
Why do I get two different answers for this counting problem?
Intersection point of 2 lines defined by 2 points each
Theorems that impeded progress
Can I make popcorn with any corn?
Important Resources for Dark Age Civilizations?
Which country benefited the most from UN Security Council vetoes?
Awk extract fields with multiple seperator [on hold]
Printing fields using awkAwk with multiple delimitersExtract multiple lines with secondary keyword searchExtract 2 fields from 2 different linesawk command with multiple commandsMultiple `awk` statements with pipes `|` ?awk to match and cut out fields with alternating delimiterawk, awk with variables, filegrep comma separated-fields with multiple conditionsTrouble pasting specific fields using awk
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have lines in a file like below
AB: 20190131 13 J-1|19:30:00.000000000 18:06:00.000000000 123466 50 @TEST . "" 1234 - I . ".." "" "" "TEST TEXT 1" "TEXT 2: SAMPLE TEXT I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find f.==Required file.csv.gz FIELD*SERVER-TIME*05:29:51.981378000" "" NoTime
I want to extract third field seperated by space that is 13 and Required file.csv.gz which is the first field for field separator ==
Required output is
13,Required file.csv.gz
I am able to extract file name with below command
awk -F "==" '/.csv.gz/print $2' | awk 'print $1'
But unable to get the file ID 13. Unable to use space as delimitter as text after TEXT2: don't have fixed words.
Filenames in file can be "Required file.csv.gz", "Required_file.csv.gz" or "This is a required file.csv.gz".
awk files
put on hold as unclear what you're asking by RoVo, msp9011, nwildner, Michael Homer, Inian 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
I have lines in a file like below
AB: 20190131 13 J-1|19:30:00.000000000 18:06:00.000000000 123466 50 @TEST . "" 1234 - I . ".." "" "" "TEST TEXT 1" "TEXT 2: SAMPLE TEXT I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find f.==Required file.csv.gz FIELD*SERVER-TIME*05:29:51.981378000" "" NoTime
I want to extract third field seperated by space that is 13 and Required file.csv.gz which is the first field for field separator ==
Required output is
13,Required file.csv.gz
I am able to extract file name with below command
awk -F "==" '/.csv.gz/print $2' | awk 'print $1'
But unable to get the file ID 13. Unable to use space as delimitter as text after TEXT2: don't have fixed words.
Filenames in file can be "Required file.csv.gz", "Required_file.csv.gz" or "This is a required file.csv.gz".
awk files
put on hold as unclear what you're asking by RoVo, msp9011, nwildner, Michael Homer, Inian 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Please, read MCVE
– Gilles Quenot
2 days ago
I don't see howRequired file.csv.gz
is the first field for-F "=="
– RoVo
2 days ago
Please drag the line for complete sentence
– upkar
2 days ago
your command outputs justRequired
.
– RoVo
2 days ago
How would you know that the file name isRequired file.csv.gz
instead ofRequired_file.csv.gz
orThis is a required file.csv.gz
if after your file name is another space ? What are possible file names ? For now, answers can only cover your current exact example.
– RoVo
2 days ago
|
show 2 more comments
I have lines in a file like below
AB: 20190131 13 J-1|19:30:00.000000000 18:06:00.000000000 123466 50 @TEST . "" 1234 - I . ".." "" "" "TEST TEXT 1" "TEXT 2: SAMPLE TEXT I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find f.==Required file.csv.gz FIELD*SERVER-TIME*05:29:51.981378000" "" NoTime
I want to extract third field seperated by space that is 13 and Required file.csv.gz which is the first field for field separator ==
Required output is
13,Required file.csv.gz
I am able to extract file name with below command
awk -F "==" '/.csv.gz/print $2' | awk 'print $1'
But unable to get the file ID 13. Unable to use space as delimitter as text after TEXT2: don't have fixed words.
Filenames in file can be "Required file.csv.gz", "Required_file.csv.gz" or "This is a required file.csv.gz".
awk files
I have lines in a file like below
AB: 20190131 13 J-1|19:30:00.000000000 18:06:00.000000000 123466 50 @TEST . "" 1234 - I . ".." "" "" "TEST TEXT 1" "TEXT 2: SAMPLE TEXT I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find f.==Required file.csv.gz FIELD*SERVER-TIME*05:29:51.981378000" "" NoTime
I want to extract third field seperated by space that is 13 and Required file.csv.gz which is the first field for field separator ==
Required output is
13,Required file.csv.gz
I am able to extract file name with below command
awk -F "==" '/.csv.gz/print $2' | awk 'print $1'
But unable to get the file ID 13. Unable to use space as delimitter as text after TEXT2: don't have fixed words.
Filenames in file can be "Required file.csv.gz", "Required_file.csv.gz" or "This is a required file.csv.gz".
awk files
awk files
edited 2 days ago
Kusalananda♦
140k17261434
140k17261434
asked 2 days ago
upkarupkar
16119
16119
put on hold as unclear what you're asking by RoVo, msp9011, nwildner, Michael Homer, Inian 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as unclear what you're asking by RoVo, msp9011, nwildner, Michael Homer, Inian 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Please, read MCVE
– Gilles Quenot
2 days ago
I don't see howRequired file.csv.gz
is the first field for-F "=="
– RoVo
2 days ago
Please drag the line for complete sentence
– upkar
2 days ago
your command outputs justRequired
.
– RoVo
2 days ago
How would you know that the file name isRequired file.csv.gz
instead ofRequired_file.csv.gz
orThis is a required file.csv.gz
if after your file name is another space ? What are possible file names ? For now, answers can only cover your current exact example.
– RoVo
2 days ago
|
show 2 more comments
1
Please, read MCVE
– Gilles Quenot
2 days ago
I don't see howRequired file.csv.gz
is the first field for-F "=="
– RoVo
2 days ago
Please drag the line for complete sentence
– upkar
2 days ago
your command outputs justRequired
.
– RoVo
2 days ago
How would you know that the file name isRequired file.csv.gz
instead ofRequired_file.csv.gz
orThis is a required file.csv.gz
if after your file name is another space ? What are possible file names ? For now, answers can only cover your current exact example.
– RoVo
2 days ago
1
1
Please, read MCVE
– Gilles Quenot
2 days ago
Please, read MCVE
– Gilles Quenot
2 days ago
I don't see how
Required file.csv.gz
is the first field for -F "=="
– RoVo
2 days ago
I don't see how
Required file.csv.gz
is the first field for -F "=="
– RoVo
2 days ago
Please drag the line for complete sentence
– upkar
2 days ago
Please drag the line for complete sentence
– upkar
2 days ago
your command outputs just
Required
.– RoVo
2 days ago
your command outputs just
Required
.– RoVo
2 days ago
How would you know that the file name is
Required file.csv.gz
instead of Required_file.csv.gz
or This is a required file.csv.gz
if after your file name is another space ? What are possible file names ? For now, answers can only cover your current exact example.– RoVo
2 days ago
How would you know that the file name is
Required file.csv.gz
instead of Required_file.csv.gz
or This is a required file.csv.gz
if after your file name is another space ? What are possible file names ? For now, answers can only cover your current exact example.– RoVo
2 days ago
|
show 2 more comments
3 Answers
3
active
oldest
votes
You can use match()
with RSTART, RLENGTH and substr()
:
awk 'match($0,/==.*?.csv.gz/)print $3","substr($0, RSTART+2, RLENGTH-2)' file
Where
we use match()
function to find the sub-string matching the pattern /==.*?.csv.gz/
. For any matched lines, we will get RSTART and RLENGTH to identify the location and length of the matched text, then use substr($0, RSTART+2, RLENGTH-2)
to retrieve the text (+2
and -2
to remove the leading '==' from the matched text).
New contributor
Perfect, Thanks !!!
– upkar
2 days ago
add a comment |
Try this,
Option 1:
awk 'gsub(/f.==/, ""); print $3","$(NF-4)" "$(NF-3)' file
13,Required file.csv.gz
gsub
will substitute "f.==" with null.- print 3rd fields from start and 4th and 3rd filed from the end of the line
Option 2:
echo "`awk ' print $3' file && awk -F '==' 'print $2' file| awk 'print $1" "$2'`" | tr 'n' ','
- print the 3rd column with space as delimiter.
- parse 2nd column with "==" as delimiter and from that print 1st and 2nd column with space as delimiter.
- the transpose newline with comma
Note: option2 is only for one line input.
Can you plz explain how it works
– upkar
2 days ago
@upkar check my update
– msp9011
2 days ago
add a comment |
With one awk :
awk '
printf "%s,", $3
match($0, /Required [a-z]+.csv.gz/, a)
print a[0]
' /tmp/file
With 2 commands :
awk 'printf "%s,", $3' /tmp/file
grep -oP 'f.==KRequired w+.csv.gz' /tmp/file
Output
13,Required file.csv.gz
Missed a print statement in awk
– Gilles Quenot
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use match()
with RSTART, RLENGTH and substr()
:
awk 'match($0,/==.*?.csv.gz/)print $3","substr($0, RSTART+2, RLENGTH-2)' file
Where
we use match()
function to find the sub-string matching the pattern /==.*?.csv.gz/
. For any matched lines, we will get RSTART and RLENGTH to identify the location and length of the matched text, then use substr($0, RSTART+2, RLENGTH-2)
to retrieve the text (+2
and -2
to remove the leading '==' from the matched text).
New contributor
Perfect, Thanks !!!
– upkar
2 days ago
add a comment |
You can use match()
with RSTART, RLENGTH and substr()
:
awk 'match($0,/==.*?.csv.gz/)print $3","substr($0, RSTART+2, RLENGTH-2)' file
Where
we use match()
function to find the sub-string matching the pattern /==.*?.csv.gz/
. For any matched lines, we will get RSTART and RLENGTH to identify the location and length of the matched text, then use substr($0, RSTART+2, RLENGTH-2)
to retrieve the text (+2
and -2
to remove the leading '==' from the matched text).
New contributor
Perfect, Thanks !!!
– upkar
2 days ago
add a comment |
You can use match()
with RSTART, RLENGTH and substr()
:
awk 'match($0,/==.*?.csv.gz/)print $3","substr($0, RSTART+2, RLENGTH-2)' file
Where
we use match()
function to find the sub-string matching the pattern /==.*?.csv.gz/
. For any matched lines, we will get RSTART and RLENGTH to identify the location and length of the matched text, then use substr($0, RSTART+2, RLENGTH-2)
to retrieve the text (+2
and -2
to remove the leading '==' from the matched text).
New contributor
You can use match()
with RSTART, RLENGTH and substr()
:
awk 'match($0,/==.*?.csv.gz/)print $3","substr($0, RSTART+2, RLENGTH-2)' file
Where
we use match()
function to find the sub-string matching the pattern /==.*?.csv.gz/
. For any matched lines, we will get RSTART and RLENGTH to identify the location and length of the matched text, then use substr($0, RSTART+2, RLENGTH-2)
to retrieve the text (+2
and -2
to remove the leading '==' from the matched text).
New contributor
New contributor
answered 2 days ago
jxcjxc
1362
1362
New contributor
New contributor
Perfect, Thanks !!!
– upkar
2 days ago
add a comment |
Perfect, Thanks !!!
– upkar
2 days ago
Perfect, Thanks !!!
– upkar
2 days ago
Perfect, Thanks !!!
– upkar
2 days ago
add a comment |
Try this,
Option 1:
awk 'gsub(/f.==/, ""); print $3","$(NF-4)" "$(NF-3)' file
13,Required file.csv.gz
gsub
will substitute "f.==" with null.- print 3rd fields from start and 4th and 3rd filed from the end of the line
Option 2:
echo "`awk ' print $3' file && awk -F '==' 'print $2' file| awk 'print $1" "$2'`" | tr 'n' ','
- print the 3rd column with space as delimiter.
- parse 2nd column with "==" as delimiter and from that print 1st and 2nd column with space as delimiter.
- the transpose newline with comma
Note: option2 is only for one line input.
Can you plz explain how it works
– upkar
2 days ago
@upkar check my update
– msp9011
2 days ago
add a comment |
Try this,
Option 1:
awk 'gsub(/f.==/, ""); print $3","$(NF-4)" "$(NF-3)' file
13,Required file.csv.gz
gsub
will substitute "f.==" with null.- print 3rd fields from start and 4th and 3rd filed from the end of the line
Option 2:
echo "`awk ' print $3' file && awk -F '==' 'print $2' file| awk 'print $1" "$2'`" | tr 'n' ','
- print the 3rd column with space as delimiter.
- parse 2nd column with "==" as delimiter and from that print 1st and 2nd column with space as delimiter.
- the transpose newline with comma
Note: option2 is only for one line input.
Can you plz explain how it works
– upkar
2 days ago
@upkar check my update
– msp9011
2 days ago
add a comment |
Try this,
Option 1:
awk 'gsub(/f.==/, ""); print $3","$(NF-4)" "$(NF-3)' file
13,Required file.csv.gz
gsub
will substitute "f.==" with null.- print 3rd fields from start and 4th and 3rd filed from the end of the line
Option 2:
echo "`awk ' print $3' file && awk -F '==' 'print $2' file| awk 'print $1" "$2'`" | tr 'n' ','
- print the 3rd column with space as delimiter.
- parse 2nd column with "==" as delimiter and from that print 1st and 2nd column with space as delimiter.
- the transpose newline with comma
Note: option2 is only for one line input.
Try this,
Option 1:
awk 'gsub(/f.==/, ""); print $3","$(NF-4)" "$(NF-3)' file
13,Required file.csv.gz
gsub
will substitute "f.==" with null.- print 3rd fields from start and 4th and 3rd filed from the end of the line
Option 2:
echo "`awk ' print $3' file && awk -F '==' 'print $2' file| awk 'print $1" "$2'`" | tr 'n' ','
- print the 3rd column with space as delimiter.
- parse 2nd column with "==" as delimiter and from that print 1st and 2nd column with space as delimiter.
- the transpose newline with comma
Note: option2 is only for one line input.
edited 2 days ago
answered 2 days ago
msp9011msp9011
4,58044167
4,58044167
Can you plz explain how it works
– upkar
2 days ago
@upkar check my update
– msp9011
2 days ago
add a comment |
Can you plz explain how it works
– upkar
2 days ago
@upkar check my update
– msp9011
2 days ago
Can you plz explain how it works
– upkar
2 days ago
Can you plz explain how it works
– upkar
2 days ago
@upkar check my update
– msp9011
2 days ago
@upkar check my update
– msp9011
2 days ago
add a comment |
With one awk :
awk '
printf "%s,", $3
match($0, /Required [a-z]+.csv.gz/, a)
print a[0]
' /tmp/file
With 2 commands :
awk 'printf "%s,", $3' /tmp/file
grep -oP 'f.==KRequired w+.csv.gz' /tmp/file
Output
13,Required file.csv.gz
Missed a print statement in awk
– Gilles Quenot
2 days ago
add a comment |
With one awk :
awk '
printf "%s,", $3
match($0, /Required [a-z]+.csv.gz/, a)
print a[0]
' /tmp/file
With 2 commands :
awk 'printf "%s,", $3' /tmp/file
grep -oP 'f.==KRequired w+.csv.gz' /tmp/file
Output
13,Required file.csv.gz
Missed a print statement in awk
– Gilles Quenot
2 days ago
add a comment |
With one awk :
awk '
printf "%s,", $3
match($0, /Required [a-z]+.csv.gz/, a)
print a[0]
' /tmp/file
With 2 commands :
awk 'printf "%s,", $3' /tmp/file
grep -oP 'f.==KRequired w+.csv.gz' /tmp/file
Output
13,Required file.csv.gz
With one awk :
awk '
printf "%s,", $3
match($0, /Required [a-z]+.csv.gz/, a)
print a[0]
' /tmp/file
With 2 commands :
awk 'printf "%s,", $3' /tmp/file
grep -oP 'f.==KRequired w+.csv.gz' /tmp/file
Output
13,Required file.csv.gz
edited 2 days ago
answered 2 days ago
Gilles QuenotGilles Quenot
16.5k14053
16.5k14053
Missed a print statement in awk
– Gilles Quenot
2 days ago
add a comment |
Missed a print statement in awk
– Gilles Quenot
2 days ago
Missed a print statement in awk
– Gilles Quenot
2 days ago
Missed a print statement in awk
– Gilles Quenot
2 days ago
add a comment |
1
Please, read MCVE
– Gilles Quenot
2 days ago
I don't see how
Required file.csv.gz
is the first field for-F "=="
– RoVo
2 days ago
Please drag the line for complete sentence
– upkar
2 days ago
your command outputs just
Required
.– RoVo
2 days ago
How would you know that the file name is
Required file.csv.gz
instead ofRequired_file.csv.gz
orThis is a required file.csv.gz
if after your file name is another space ? What are possible file names ? For now, answers can only cover your current exact example.– RoVo
2 days ago