Tagged Questions
2
votes
3answers
143 views
Easy way to parse syslog date format
I'd like to write a script that analyses the last week's syslog.
But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial.
Is there a way ...
3
votes
2answers
55 views
Automated partition selection in bash script
I'm trying to write a bash script to run from Linux on a CD or flashdrive that can mount Windows and change stuff, but I don't know how to go about detecting which partition/drive is Windows.
My best ...
2
votes
2answers
90 views
Using bash shell function inside AWK
Is it possible to use bash function inside AWK somehow?
Example file (string, int, int, int)
Mike 247808 247809 247810
Trying to convert values from decimal to hexadecimal.
Function defined ...
3
votes
1answer
156 views
Pass colors from ls through pipe to awk 'print' statement
This is a follow-up to my question from yesterday, Show sum of file sizes in directory listing.
Thanks to Zero Piraeus and a point in the right direction by Mauritz Hansen, I now have
function ...
5
votes
4answers
184 views
Show sum of file sizes in directory listing
The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
1answer
87 views
Safely convert unicode strings to printable characters
I have many HTML files containing mixed unicode strings like \303\243 and printable characters like %s. What I'd like to do is converting the unicode strings into printable characters in a safe way.
...
1
vote
2answers
53 views
How do I get a field in bash's job list using awk?
I wanted to write a function to retrieve a field from the list of background jobs in bash. For example to get a specific argument.
Let's say I send vim to the background, so "jobs" displays this ...
2
votes
3answers
197 views
Bash commands/script to remove a line from CSV with duplicate in column
I have a lot CSV files that I have combined. However, there are duplicates, but the entire line is not duplicated. I do have a column that I want to use as the criteria to search for a duplicate. ...
1
vote
0answers
145 views
Processing shell script options with awk
I'm looking for way to process shell script arguments that is cleaner and more "self documenting" than getopt/getopts.
It would need to provide...
Full support of long options with or without a ...
1
vote
0answers
141 views
Conky - string formatting
I have conky the record:
${color lightblue} Down: ${downspeed wlan0} Up: ${upspeed wlan0}
Conky prints link speed, but the text moves:
Down: OB Up: OB
Down: 60B Up: 60B
Down: 148B Up: 148B
...
1
vote
1answer
284 views
Validate Unix Timestamp using BASH
My google-fu has failed me so I'm hoping someone here can point me in the right direction. I'm in the middle of doing some data validation efforts and I suspect the system is recording some invalid ...
2
votes
1answer
406 views
Bash variable in Awk script
I have this flat file database(ff_servers.db) with following contents:
192.168.154.2 Alaska hp
192.168.157.3 Colorado dell
192.168.156.3 hawaii hp
From command line, I could run:
awk ...
1
vote
1answer
84 views
how to add a description in footer
I enjoy learning how to modify files with awk, sed, and bash. However, I know it could cause issues down the road and I would like to be prepared with a log inside the file. I was thinking about how ...
2
votes
3answers
272 views
Awk to output read file
I havent stepped into awk yet but it is on my plate for learning this coming year. I asked a previous question that led me to awk and it works. However, I am unsure how to input all file types and ...
1
vote
3answers
697 views
Print lines where first field has only four characters using regex in awk?
John Goldenrod:(916) 348-4278:250:100:175
Chet Main:(510) 548-5258:50:95:135
Tom Savage:(408) 926-3456:250:168:200
Elizabeth Stachelin:(916) 440-1763:175:75:300
output should contain the lines ...
1
vote
1answer
108 views
renaming diverse files
I store files named like this: word-word2-word3-word4.txt . The number of "words" varies from file to file.
I want to replace certain of the dashes with pluses e.g word+word2-word3+word4.txt
I want ...
0
votes
2answers
160 views
Easiest way to find/replace in a file using a list?
I have a file, foo.txt, and a regexp I want to find in that file. Each time I find the regexp, I want to take a line from another file, bar.txt, and substitute it in for the regexp match I found in ...
1
vote
2answers
239 views
List info about files/directories with spaces
I am trying to use ls to get information about files and directories. My current command fails to properly get the name whenever a file/directory has a space.
I am using this to list all ...
5
votes
2answers
177 views
Use a script parameter in awk
Here is my script (to find the files that contain a specified pattern) :
find . -type f -exec awk -v vawk="$1" '/'"$vawk"'/ {c++} c>0 {print ARGV[1] ; exit 0 } END { if (! c) {exit 1}}' \{\} \;
...
1
vote
3answers
691 views
bash merge 2 lists removing duplicated
I have an embedded linux system using Busybox (OpenWRT) - so commands are limited. I have two files that look like:
first file
aaaaaa
bbbbbb
cccccc
mmmmmm
nnnnnn
second file
mmmmmm
nnnnnn
...
4
votes
6answers
252 views
What is the easiest way to check if column A and B values goes both ways with AWK? [closed]
What is the easiest way to check if column A and B values goes both ways?
Output to check:
Mike John
John Mike
Pamela Barbara
Barbara Pamela
Mike Paul
Roger Paul
Desired output
Mike <-> ...
5
votes
1answer
829 views
Fast elimination of duplicate lines across multiple files
I have a huge amount of data in which each (data-)line should be unique.
There are a lot of files in one folder in which this is already true. It is about 15GB splitted into roughly 170 files with ...
15
votes
3answers
966 views
Piping from grep to awk not working
I am trying to grep the ongoing tail of file log and get the nth word from a line. Example file:
$ cat > test.txt <<EOL
Beam goes blah
John goes hey
Beam goes what?
John goes forget it
Beam ...
1
vote
3answers
599 views
how to sum output of awk or other expression with xargs
Suppose i have the following bash shell script:
#!/bin/bash
export count=0;
for i in `ls ./mydoc` ;do
pdfinfo ./mydoc/$i | egrep Pages |awk {'print $2'} |xargs -+ $count ;
...
11
votes
1answer
1k views
Making a progressbar with “dialog” from rsync output
I'm looking for a way to filter/redirect rsync output in a manner where it can be fed to the "dialog --gauge" command, so I can get a nice looking progressbar during file sync.
Currently I have only ...
3
votes
2answers
1k views
Working with columns - awk and sed
I am trying to parse a text file that is generated by an expec script that
pulls down some information from a switch.
Here is a sample output:
192 0000.0000.0000 1/g23 Dynamic ...
4
votes
2answers
210 views
How can I get awk to print both matches and non-matches?
Basically, all I want to do is alter outputs if the input matches a filter, but the part being altered isn't what is being filtered (or I would use sed). The problem so far is that my awk is only ...
8
votes
3answers
819 views
How to sort the string which combined with string + numeric using bash script?
This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected.
/home/files/profile1
/home/files/profile10
/home/files/profile11
...
3
votes
6answers
883 views
Text file look-up by column
I have a file in this format:
[#] OWNER_NAME NAME SIZE
[6] Robottinosino Software 200
[42] Robottinosino Ideas worth zero 188
[12] ...
3
votes
1answer
475 views
Make awk use bash with the system() command
Is there a way to make awk use bash instead of sh when running system commands using the system() call?
I want to use some bash-specific features such as [[ ]] and < > string comparison operators:
...
16
votes
9answers
1k views
Remove duplicate $PATH entries with awk command
I am trying to write a bash shell function that will allow me to remove duplicate copies of directories from my path environment.
I was told that it is possible to achieve this with a one line ...
1
vote
1answer
525 views
Extract marked strings from text file using Bash
I have files which are of the following style - these are parametrised configuration files; the values within the #characters are replaced with real values from a database depending on environment.
...
2
votes
2answers
159 views
How do I ad an if statement (regarding punctuation in a word) to this bash script
I have this bash script
#!/bin/bash
cat $@ | while read line
do
for word in $line
do
echo $word | circling-the-square
# here's where i need to add the if statement:
...
2
votes
2answers
385 views
How can I turn ugly output into pretty, useful information?
How can I turn this ugly output into pretty, useful data?
The output:
/* ---------- TA#box#AbC_p ---------- */
insert_job: TA#box#AbC_p job_type: a
#owner: bob
permission: gx
date_conditions: 1
...
0
votes
2answers
769 views
Using awk to process ls output with spaces in filenames/paths
All,
I have a script in which I use find command to filter out all png files in a given folder and list them along with their size. I want the output in the following format:
someFile.png => 1.2K ...
3
votes
3answers
264 views
swapping fields in columns by fixed pattern (yes, no, no, yes)
I want to produce a following list of pages (for imposition work); (number of pages is variable, but I make a sample of my needs using a list of 16 pages, logic is the same for longer lists)
1,16
8,9
...
0
votes
1answer
278 views
Using Awk To Parse Individual Lines
Here is the output from qacct -o
Total : OWNER WALLCLOCK UTIME STIME CPU MEMORY IO IOW ...
1
vote
3answers
497 views
Combining Awk with Curl
How would I set my curl statement so that it puts the value of each $3 in for the username, and the value of each $4 for the wallclock information?
Some further information
I am trying to take the ...
3
votes
2answers
491 views
simple script rotating table
I'm trying to write a simple script, that just rotates csv table.
I mean I have some file:
head1;head2;head3
field11;field12;field13
and so on.
All I want, just to make my file
...
5
votes
3answers
568 views
Is there a more elegant way to count words and assign that count to variables?
I have a script:
#!/bin/bash
/root/xiotech status > xiostatus.tmp
SyncCount=$(grep -c Sync xiostatus.tmp)
PauseCount=$(grep -c paused xiostatus.tmp)
CopyingCount=$(grep -c Copying xiostatus.tmp)
...
4
votes
2answers
345 views
Replace one line with STDIN in a Makefile
One Makefile target is supposed to be in charge of:
grabbing the output of $ perl Markdown.pl src/index.md (markdown to html)
using that string to replace one line, something like CONTENT ...
2
votes
3answers
416 views
How to truncate the second column from a dot (.)?
INPUT:
10.175.192.16 vgxyxgf.de.foo.net asdf 34efg
10.175.192.17 sdtds.de.foo.net xyyxv e5432
10.175.243.20 asdfycfb.us.foo.net dfvasf 34525
OUTPUT:
10.175.192.16 vgxyxgf
...
3
votes
4answers
294 views
Align a hex text file at 9 bytes each line
I want to align the selected portion of a text file at 9 bytes each column.
For example suppose my text file looks like below.
00 2f c6 b8 29 fd 02 37 11 00 9f 74 34 0b 60 72 38 20 00 9e 61 33 8e ...
4
votes
3answers
3k views
Delete range of lines above pattern with sed (or awk)
I have the following code that will remove lines with the pattern banana and 2 lines after it:
sed '/banana/I,+2 d' file
So far, so good! But I need it to remove 2 lines before banana, but I can't ...
2
votes
3answers
833 views
Trouble getting awk output in for loop
I'm trying to create a script that will check a website for a word. I have a few to check so I'm trying to input them via another file.
The file is called "testurls". In the file I list the keyword ...
10
votes
6answers
2k views
How to print the longest line in a file?
I'm looking for the simplest method to print the longest line in a file. I did some googling and surprisingly couldn't seem to find an answer. I frequently print the length of the longest line in a ...
2
votes
2answers
382 views
Adding 2 lines in text file stanza
I have a text file divided in stanzas.
Each stanza starts with a [keyword] and ends with a blank line. Something like this:
[keyword1]
param1 = value1
param2 = value2
param3 = value3
[keyword2]
...
-2
votes
2answers
229 views
How to delete the second column from this input?
INPUT
bix.hu. 42433 IN A 193.239.149.1
bix.hu. 42433 IN MX 10 deneb.iszt.hu.
bix.hu. 42433 IN NS ns.iszt.hu.
bix.hu. 42433 IN NS ns.iszt.hu.
bix.hu. ...
5
votes
2answers
249 views
How would I sort these directory names numerically?
I'm aware that I can somehow sort this output numerically (so cpu1/ follows cpu0/) ... I could probably get something to work eventually by splitting up the string various ways with awk, but is there ...
1
vote
4answers
1k views
Increment number in bash variable string
VERSION="4.0beta12"
NEXT_VERSION=?????
Writing an automatic release script, I have the current version in a variable $VERSION, and I would like to calculate the next version as $NEXT_VERSION.
Rule: ...