Skip to content
Advertisement

Tag: awk

Converting date format in bash

I have similar different file of the format backup_2016-26-10_16-30-00 is it possible to rename using bash script to backup_26-10-2016_16:30:00 for all files. Kindly suggest some method to fix this. Original file: backup_2016-30-10_12-00-00 Expected output: backup_30-10-2016_12:00:00 Answer To perform only the name transformation, you can use awk: As fedorqui points out in a comment, awk’s printf function may be tidier in

Storing awk manipulation in variable

I have two text files in tab delimted format like following. file_1 file_2 these two file contents were stored into two different variables. Now I would like extract the lines which has “+” symbol in column 4 and store it in the variable and later print it. But it throws me error message: Here is my code which I tried

how to calculate percentage in shell

I would like to calculate percentage in shell. But I can’t do it. My script is It is neither showing any value nor terminating when executing this script. Answer awk will give you an n1 illegal field name if you do that, as it’s inside single quotes. Also, to avoid awk keep reading stdin you should pass /dev/null as file.

Subtract a constant number from a column

I have two large files (~10GB) as follows: file1.csv file2.csv I want to subtract 1 from the “id” columns of these files: file1_updated.csv file2_updated.csv I have tried awk ‘{print ($1 – 1) “,” $0}’ file2.csv, but did not get the correct result: Answer You’ve added an extra column in your attempt. Instead set your first field $1 to $1-1: That

partial merging 2 text file in linux

I have 2 text file which I want to merge them in a new file. my first file is look like and second file = and my expected output like, I mean mapping part of 9th column string from first line with 1st column of second file, should be like : Also, I wanted to keep line from first file

Bash: transform key-value lines to CSV format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago. Improve this question Editor’s note: I’ve clarified the problem definition, because I think the problem is an interesting one, and this question deserves to be reopened. I’ve got

Pass argument to awk inside do loop

I have a large number of tab-separated text files containing a score I’m interested in in the second column: test_score_1.txt test_score_2.txt I want to check if I have Titles with a score smaller than a number I define. The following code defines my score in the script and works: check_score_1 If I try to pass an argument to awk like

printf in awk with Umlauts doesn’t work

Can somebody please give me an alternative to the following awk statement. As soon as I give a “n” for string, it skips after Umlaut. I don’t want to use gsub because I have many special characters and don’t want to write a script for this. Also if not in awk, can somebody help me in other languages? Answer The

Advertisement