How can I comment out lines from a certain pattern and N lines onwards?
int var1;
int var2;
int var3;
int var4;
int var5;
I want to comment out 3 lines including var2 (and not according to their content!):
int var1;
// int var2;
// int var3;
// int var4;
int var5;
...
I want the awk to interpret the variable as follows
#!/bin/bash
file=tau
f=2.54
order=even
awk '{sum+=$2}; END {print '${file}_${f}_${order}_v1.xls', sum/NR}'
${file}_${f}_${order}_v1.xls >> safe/P-state-summary.xls
I want the desired output as follows -
tau_2.54_even_v1.xls sum/NR
Can anybody help me out with this ?
...
Let as say I want different files starting from "process" till next "process.
For example
Input file
Process=0
We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.
If your question is about this website, ask it on meta instead.
Process=1
We prefer questions that can be answered, not...
The following command on my Mac (10.6) gives me an undefined function error:
$ awk 'BEGIN{now=strftime("%D", systime()); print now}'
awk: calling undefined function strftime
source line number 1
On a Red Hat system, I get the expected result:
$ awk 'BEGIN{now=strftime("%D", systime()); print now}'
12/01/09
What's the deal here?
...
I type in this command frequently, and was trying to alias it, and couldn't for some reason.
for FILE in `svn stat | awk '{print $2}'`; do svn revert $FILE; done
This obviously does a large number of svn reverts.
when I alias it:
alias revert_all="for FILE in `svn stat | awk '{print $2}'`; do svn revert $FILE; done"
svn stat runs ...
I have a tgz file which contains a version file, version.txt. This file has only one line "version=1.0.0". This tgz file is present in two different directories and has the same name.
My requirement is that I need to use bash script and awk to determine which of these two tgz files is of the latest version. i.e. tgz file having 1.0.0 is...
Hi there!
I'm processing a manpage in nroff format with awk to extract the options to each command... I figured out that the options start with \fB, followed by the actual option, and maybe \fP and option arguments and so on...
Example:
\fB\-\-author\fR
I started writing an awk-script, specifing FS = "\fB" ... well, it didn't work.....
I have data like this:
# data_display
ab as we hj kl
12 34 45 83 21
45 56 98 45 09
I need just the first column alone, and only the rows starting with numbers.
I now use:
# data_display | awk '{ print $1 }' | grep "^[0-9]"
Is there any way to optimise it more, like using the regex in awk itself?
I am very new to awk.
Tha...
I'm trying to format the output of ls -la to only contain files modified in December and output them nicely, this is what they currently look like:
ls -la | awk {'print $6,$7,$8,$9,$10'} | grep "Dec" | sort -r | head -5
Dec 4 20:15 folder/
Dec 4 19:51 ./
Dec 4 17:42 Folder\ John/
Dec 4 16:19 Homework\ MAT\ 08/
Dec 4 16:05 Folder\ Smith...
I need to execute a command per line of some file. For example:
file1.txt 100 4
file2.txt 19 8
So my awk script need to execute something like
command $1 $2 $3
and save the output of command $1 $2 $3, so system() will not work and neither will getline. (I can't pipe the output if I do something like this.)
The restriction to this ...
I want to extract the URL from within the anchor tags of an html file.
This needs to be done in BASH using SED/AWK. No perl please.
What is the easiest way to do this?
Thanks a lot.
...
Hi - I have to process text files 10-20GB in size of the format:
field1 field2 field3 field4 field5
I would like to parse the data from each line of field2 into one of several files; the file this gets pushed into is determined line-by-line by the value in field4. There are 25 different possible values in field2 and hence 25 different f...
I would like to write a small script using the standard linux shell scripting tools (sed, awk, etc.) to create one output file per line of input. For example, given the following input file 'input':
line1
line2
line3
I would like to run the command.
$ cat input | my_prog
Where 'my_prog' is a script that creates three output files, ...
How can you run AWK in Vim's selection of the search?
My pseudo-code
%s/!awk '{ print $2 }'//d
I am trying to delete the given column in the file.
...
How do I display data from the beginning of a file until the first occurrence of a regular expression?
For example, if I have a file that contains:
One
Two
Three
Bravo
Four
Five
I want to start displaying the contents of the file starting at line 1 and stopping when I find the string "B*". So the output should look like this:
One
T...
I'd like to copy commands from my recent command history into a file, but the history looks like this:
568 find . -name "*.txt" -mtime -1 -print -exec awk '$9 != "" && NR <= 10' {} \;
569 find . -name "*.txt" -mtime -1 -print -exec awk '$9 != "" && n < 10 {print; n++}' {} \;
570 history 10
I want to strip off the numbers on the lef...
Hi All,
I am currently working as a software developer mainly coding in PHP & JS at the current job. I have about 2 years of experience, mostly in web development and i am trained in Java. Have some basic work experience in Struts. I recently have 2 job offers. Both are respectable companies with leaders in their industry. IT & Logisti...
I'm trying to parse json returned from a curl request, like sp:
curl 'http://twitter.com/users/username.json' | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}'
I have it set working where it splits the json into fields, i.e. the above returns
% ...
"geo_enabled":false
"friends_count":245
...
I cannot solve a very simple problem. My data file looks like:
Crap Crap 0.123456789D+09 Crap Crap
Crap Crap 0.123456798D+09 Crap Crap
I need to use AWK to subtract the number in the third column; the SECOND row minus the FIRST row.
I tried:
cat crap.txt | awk '{ A[NR-1] = $3 } END { print A[1] - A[0] }'
to no success. Maybe the f...
Hi,
I want to run the system command in a awk script and get its output stored in a variable. I've been trying to do this, but the command's output always goes to shell and I'm not able to capture it. Any ideas on how this can be done?
Example:
$ date | awk --field-separator=! {$1 = system("strip $1"); /*more processing*/}
Should ...