All Questions
88 questions
0
votes
3
answers
195
views
How to edit a string matching a pattern in a specific field on the condition another string is not present on the same line
I need to edit the string "NA" to "Na" only if it is in the 6th field of a file. I can currently achieve this with:
awk '{gsub("NA","Na",$6)}1' $filename
...
1
vote
3
answers
363
views
awk print between lines when "/" is part of the name
I need to print lines between those that contain a "/" in the name.
I tried with:
awk '/+SOLUTION/ESTIMATES/,/-SOLUTION/ESTIMATES/' $F > fil$F
and
awk '/+SOLUTION"/"ESTIMATES/,/...
0
votes
4
answers
844
views
how to print first word from a string with multiple words without space?
I have a shell script to print appimage filenames inside a folder like this
#! /bin/bash
Dir="$HOME/Applications/"
Dir2="$HOME/Downloads/"
cd -P "$Dir"
for f in *....
3
votes
1
answer
2k
views
How to print leading zeros (padding) in awk?
I am trying to print 99.11111 as 099.11 in AWK.
I have tried the following variations without success.
$ awk '{printf ("%000.2f\n", $1);}' <<< 99.111111
99.11
$ awk '{printf ("%...
0
votes
1
answer
787
views
Quoting a string in output from awk
I am fetching a string from a file using awk as shown below. Now I would like to double quote it. Any support would be highly appreciated.
awk -F',' '{print $(NF)}' sample.csv| tail +2
output:
...
0
votes
0
answers
17
views
How to returns the correct character after manipulating the output of ps ax | grep [duplicate]
I would like to have some help writing a script (which should works on freebsd where I have sh as default) that should grab a precise character when I do a "ps ax | grep" command from the ...
0
votes
1
answer
4k
views
Awk substr index 0
I just discovered that substr() in awk accepts either 0 or 1 as the initial index in a string. I tested this in Gawk 5.1.0 and MacOS awk 20070501.
awk 'BEGIN {print substr("abcd", 0, 1)}'
...
1
vote
2
answers
6k
views
split string using a substring as delimiter and get the later part
Here is my string LIBRARY_TRGT_CANV,CANV_MATCH<anything>
I wish to get all the text after last occurance of our delimiter which is _TRGT_:
Desired output:
CANV,CANV_MATCH<anything>
------ ...
0
votes
1
answer
123
views
Need help Formatting a file having key: value [duplicate]
I have a file having the below values:
cat data.txt
server1: 'calv'
server2: 'anot'
log: '/u/log/1'
server3: 'calv'
server4: 'anot'
server5: 'secd'
server6: 'calv'
LIB_TRGT_calv,anot: '/tmp/hello.txt'
...
-1
votes
3
answers
332
views
Need to format text file and update based of key value format
I have a file having the below values:
cat data.txt
server1: calv
server2: anot
log: /u/log/1
server3: calv
server4: anot
server5: secd
server6: calv
LIB_TRGT_calv,anot: /tmp/hello.txt
LIB_TRGT_secd: /...
-1
votes
5
answers
882
views
How to make sure that the last character of each line of a file ends with single quote character
I have a file which has several lines.
I wish to update the file while making sure that the last visible character of each line of the file is a single quote '. In case not, then we should add the ...
0
votes
1
answer
1k
views
How to add single quote at the end of ONLY the last line of a file [duplicate]
I want a non-perl solution where I should be able to append a single quote ' at the last visible (non-escape characters) line of a file and save it back to the file.
cat example.txt
var1: 'funn'
var2: ...
1
vote
2
answers
966
views
Remove duplicates of specific line keeping only the first appearance of each without touching other unspecified duplicates
I'm trying to edit a text file containing several duplicates. The goal is to keep only the first match of a string and remove the rest duplicate lines of the same string.
In the example file
* Title 1
...
3
votes
2
answers
10k
views
How to search for a string in a very large file with very long lines?
It turns out I was accidentally using grep wrong yesterday. I just checked my bash history and saw what I was executing:
grep search-string-here -f large-file-with-long-lines.txt
And that was what ...
1
vote
2
answers
73
views
Increment mountpoint name with awk
I am currently writing a script that makes mounting of LUKS devices easier.
In the script I do have a default mountpoint name (data_1), - however, if a mountpoint like that already exists, I want to ...