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
Can you help me with a bash script to grep string from latest files in folder. e.g. I have a folder /var/log/folder with some files, and I need to every 30 seconds grep text string some string from latest 5 files and result should be written in file /var/log/file.txt.
Thank you in advance!
This should do it
You'd need to put it into cron
cd /var/log/folder && grep "some string" `ls -c | head -n 5\` > /var/log/file.txt
if you need to append to the log, use >> rather than >
You can use below script. Just modify condition in while loop as per your requirement.
#!/bin/bash
mydir="/var/log/"
rm ${mydir}/file.txt
while [ 1 ]
do
date >> ${mydir}/file.txt
ls -tr ${mydir}/folder/ | tail -n 5 | awk -v var="${mydir}" '{print var"/folder/"$1}' | xargs grep "Some String" >> ${mydir}/file.txt
sleep 30
done
Related
This question already has answers here:
How to have the sed output side by side?
(6 answers)
Closed 8 years ago.
I try to print out the records of txt file which contains filenames(just 1 column only)
data1.txt
data2.txt
data3.txt
into one line
data1.txt data2.txt data3.txt
I have tried the following
awk -v RS='' -v OFS=',' '$1,$1' myfile.txt
awk '{print;next} {printf "%s ", $0}' myfile.txt
I have seen relevant posts but none of the advices work or I get as output
.data3.txt
instead of whole line with both 3 records
I use windows command prompt where I run awk
Any advice would be much appreciated.
You can do like this with awk
awk '{printf "%s ",$0}' file
data1.txt data2.txt data3.txt
Your text file most likely has DOS-style line endings, so you have to account for the carriage return.
awk -v ORS=" " '{sub(/\r$/, ""); print} END {ORS="\n"; print ""}' myfile.txt
Do you have to use awk? This would be simpler with tr:
tr -d '\r' < myfile.txt | tr '\n' ' '
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Is it possible to update XCode to a newer version without using the XCode GUI? So far I can only find the solution for the Xcode-CLI-tools, but not the actual XCode itself.
Run this:
curl -Ls https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex | plutil -convert json -o - - | python -mjson.tool | less
Replace the URL in this simple shell script and run it:
#!/bin/sh
OSX_VERS=$(sw_vers -productVersion | awk -F "." '{print $2}')
# Get Xcode CLI tools
# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex
TOOLS=clitools.dmg
if [ ! -f "$TOOLS" ]; then
if [ "$OSX_VERS" -eq 7 ]; then
DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg
elif [ "$OSX_VERS" -eq 8 ]; then
DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_mountain_lion_april_2013.dmg
elif [ "$OSX_VERS" -eq 9 ]; then
DMGURL=http://adcdownload.apple.com/Developer_Tools/command_line_tools_os_x_mavericks_for_xcode__late_october_2013/command_line_tools_os_x_mavericks_for_xcode__late_october_2013.dmg
fi
curl "$DMGURL" -o "$TOOLS"
fi
TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX`
hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT"
installer -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target /
hdiutil detach "$TMPMOUNT"
rm -rf "$TMPMOUNT"
rm "$TOOLS"
exit
You may be interested to ask why would anyone want to do that, but I have an use case where we have 10+ Mac Minis to manage in our build farm and we would prefer not to update one-by-one on the GUI.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a directory contains 50 files, what I need to do is append a new text to echo file, such as 'thelastline`, I don't know how to do it in mac os
sed -i '$athelastline' /path/*.file
if you are using bsd sed, the -i option would be -i ''
sed -i '' '$athelastline' /path/*.file
Find all files in current directory and below and append lastline to each:
$ find . -type f -exec sed -i '$a lastline' {} \;
Under OSX this is probably easiest with sed, but you seem to be asking about how to do this with awk, so here is a nawk compatible way of doing it (assuming you do not have strange characters in your filenames):
for f in *; do
awk '1; END { print "thelastline" }' "$f" > /tmp/tmpfile
mv /tmp/tmpfile "$f"
done
In case you are using zsh, there is a nice idiom for appending something to all files in the current directory:
<<<"thelastline" >>*
Note that multios needs to be enabled.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Any one knows how I can convert my .aiff audio file to .caf audio file?
Any Converter any link will be helpful.
Thanks in advance.
This is how to do it in terminal:
afconvert -f caff -d aacl#22050 -c 1 sound.aiff sound.caf
All files in directory script:
for f in *; do
if [ "$f" != "converttocaf.sh" ]
then
/usr/bin/afconvert -f caff -d 'aac ' -c 1 -l Mono $f
echo "$f converted"
fi
done
I have directly converted a wav file in caf file by using this command:
afconvert -f caff -d LEI16 -c 1 trampoline.wav trampoline.caf
you can also find some useful commands about the best practices to convert the file extentions on the fillowing link:
http://gamua.com/blog/2010/06/sound-on-ios-best-practices/
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have used a script like below
zgrep -i xxxx FileA|grep -o "RID=[0-9|A-Z]*"|uniq|cut -d "=" -f2|xargs -0 -I string zcat FileB| requestID="RequestID=" stringone=$requestID$string grep stringone FileB
Before the point of xargs being used my o/p is
01982893213982312 - RID 1
32103213213213213 - RID 2
32103213213213343 - RID 3
32103213213251261 - RID 4
For every RID present here, there is a corresponding line in File B. I am planning to do like the below after the:
zgrep -i xxxx FileA | grep -o "RID=[0-9|A-Z]*" | uniq | cut -d "=" -f2 | xargs|
{grep RID1 in file B, grep RID2 in file B,grep RID3 in file B, grep RID4 in file B}
Now if I do this I am getting an error
xargs: zcat: terminated by signal 13
Please help me guys