All Questions
Tagged with variable text-processing
36 questions
0
votes
0
answers
28
views
Find and replace text using sed using variable [duplicate]
I have a specific text: ==4 to be replaced by ==5. So, I initialized two variables with $i and $j with 4 and 5 respectively and used this sed command to do the work:
sed -i 's/==${i}/==${j}/g' "...
0
votes
3
answers
816
views
How can I store all the lines emitted by while loop in a single varianle in shell?
As far as I know, while loops in shell are executed in a sub-shell, so they cannot modify variables outside the loop.
I'm writing a shell script and I want to store all the internal IPs of my machine ...
0
votes
1
answer
247
views
Command working in interactive shell but not in script [duplicate]
Platform: RHEL7
Shell: Bash
Expected Result: store value as a variable
I'm trying to capture an IP from text that looks like this:
{
"ip": "12.34.56.7&...
-1
votes
2
answers
322
views
using awk to print if any three variables are true
I want the code print if any of these variables are true.
this is not my real code, it's just an example
read -p "enter protocol: " protocol
read -p "enter src ip: " srcip
read -p &...
1
vote
0
answers
194
views
Two lines are removed with sed instead of one, why? [duplicate]
I am attempting to remove lines from this text file (foo.txt):
cat
mouse
animals: 2
I want to remove the two lines from the end:
animals: 2
So I end up with this:
cat
mouse
However, when using ...
4
votes
0
answers
875
views
Using AWK to filter a file based on the numerical value of a column (where the column number and numerical value are passed in from the command line) [closed]
I have a file that is tab-delimited. I am trying to use AWK to filter the file such that the user can specify a column number and a number, and the script will return only the lines of the file (and ...
0
votes
2
answers
1k
views
How to extract specific values after a specific string and store it to different variables?
I am very new to Linux. I need to parse one summary file which generates at the end of our automation. Below is that summary file:
Total_Test_Cases_Count:25
Total_Pass:24
Total_Fail:1
...
2
votes
1
answer
9k
views
How to read a file with two columns into a script so that each line read as two variables
I have a file that has two columns like such.
cat test.txt
100 2007
FFF 1993
7E7 1994
4BB 1995
I need to input each of the lines into a script, and have the two columns assigned as separate ...
2
votes
4
answers
740
views
Convert only certain words to lowercase
Say I have a variable var whose value is fOo bar1 baR2 bArab.
How do I go about saving into another variable, say, lc_var, a version of var where all but the first word are converted to lowercase?
I ...
4
votes
4
answers
7k
views
How to allow only certain characters in a bash variable
I want to prompt the user to input a URL, but it can only contain A-Z, a-z, 0-9, &, ., /, =, _, -, :, and ?.
So, for example:
Enter URL:
$ http://youtube.com/watch?v=1234df_AQ-x
That URL is ...
1
vote
1
answer
90
views
Remove all lines that contain $PWD
I have a file that contains paths - looks like this:
/Users/a/Desktop
/Users/a/Documents
/Users/a/Documents/Work
What would be the easiest way to remove all lines that contain the current directory ($...
1
vote
2
answers
3k
views
How can I use a bash variable as a regex argument to gsub() and match()?
I have a script
#! /bin/bash
awk -v pat="$1" '{ if(match($0, pat)) {print $0} }' "$3"
awk -v pat="$1" -v rep="$2" '{gsub(pat, rep); print $0}' "$3"
I would like to run it like
myscript '\.\.+' ' ' ....
3
votes
1
answer
4k
views
Filtering Dataset with AWK based on list
I want to get rows filtered from dataframe based on the condition if they are present in the list. So far I have tried this thing.But I am getting unexpected result. The data is getting replicated and ...
0
votes
4
answers
1k
views
Get numeric value of cat output
When I save result of cat to the variable I get the following:
wfpd=$'16213\r'
How can I convert this result to numeric value in order to use it as an argument to another command
0
votes
3
answers
4k
views
Map string from var1 to var2 (lookup)
I want to do case insensitive lookup on VAR2 based on the content of VAR1 that holds some parameters in the form key:value. If a VAR1 key is present replace the value in VAR2.
For example for:
VAR1=...