I have a file like this: I want in the second colum all the rows with value 1 be changed into 4. so output should be: any suggestion? Answer You can use an awk ternary operator for that, Since by default awk splits input fields by a single white-space, we can directly check $2 to contain value as 1 if
Tag: awk
Linux: Append variable to end of line using line number as variable
I am new to shell scripting. I am using ksh. I have this particular line in my script which I use to append text in a variable q to the end of a particular line given by the variable a containing the line number . Now the variable q can contain a large amount of text, with all sorts of
AWK: variables not remembered outside actions?
I have a script that will give the percent of logins that are mine. This is done by matching all users, store to variable, then match me only (jdoe). I then use a basic operation to get the percent of logins that are mine. I get the error: ./loginPercent: line 13: eCount / totalCount: division by 0 (error token is
sed/awk to replace in a loop
I have a file called “demo” that has names in our DNS. I’m trying to loop through each line and replace the “names” with “names and ip address” (as a way of verifying dns queries) So far I have this but no luck on sed or awk command. Help appreciated. Thanks. demo “diggs” has an alias that yields one line
Get list of files whose creation date is greater than some date linux
I have these files in Hadoop and want the list of all files whose creation date is greater than 2016-11-21. I tried the command below but it’s printing all the files. How to get only the one’s which satisfy the condition Answer Pass the input date as a variable into awk expression(via -v option): The output:
Finding emails from one file in another
I want to find emails from one file listed as such: in another file listed as so: and output the lines from the second file that match with the first file also keeping in mind it needs to match the entire email from start to finish so it won’t match robertjohn@blogs.com accidently. Desired output: Thanks! Answer With grep, get the
AWK usage issue while archiving HDFS files in Hortonworks Distribution
I am trying to move files in a HDFS directory that are over 3 days old to an archiving folder in HDFS. AWK Script: Note: cmd variable would have a mv command once this script starts working Issue: Value of variable X is constant Value of Variable Y is constant Unable to get day difference between 2 date , i
Faster solution to compare files in bash
file1: and file2: I need find match file2 in file1 and print whole file1 + second column of file2 So ouptut is: My solution is very slow in bash: I am prefer FASTER any bash or awk solution. Output can be modified, but need keep all the informations (order of column can be different). EDIT: Right now it looks like
How to check for occurrences of indexes in a file onto another by column and print out the result [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago. Improve this question So i have a file1.dat with indexes i need to check (one by line) and a file2.csv file where i
Using sed piped with w command show user with the largest idle time
the w command produces something like this: I must get a sed script that prints the user with the longest idle time. But the problem is that w shows the idle time in 3 different formats: 1) in seconds: ending with an ‘s’, 2) mm:ss (not ending with ‘m’ or ‘s’), and 3) hh:mm (ending with ‘m’). So I need