Tag Info

Hot answers tagged

37

can't test right now, but ... | paste - - should do it


35

sed -n '10000000,10000020p' filename You might be able to speed that up a little like this: sed -n '10000000,10000020p; 10000021q' filename By the way, your command tail -n 10000000 filename | head 10 starts at the ten millionth line from the end of the file, while your "middle" command would seem to start at the ten millionth from the beginning ...


29

You can use nmap to run a ping scan. nmap -sP 192.168.254.* Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-09 11:32 GMT Host xyzzy.lan (192.168.254.189) is up (0.00022s latency). MAC Address: 00:0C:29:5B:A5:E0 (VMware) Host plugh.lan (192.168.254.196) is up (0.00014s latency). MAC Address: 00:0C:29:2E:78:F1 (VMware) Host foo.lan (192.168.254.200) is up. ...


15

sed '5555,7777!d' <filename> This will print lines 5555-7777 of the file inclusively. Dennis Posted the following which I agree should be faster: sed '5555,7777p; 7778q' filename The following evidence that it should be faster: $ n=1 $ while [[ n -le 100000 ]]; do echo $n >> sedtest2; n=$((n + 1)); done $ strace -e trace=read -o sed1 sed ...


15

This is where awk is the best tool. awk -F"[()]" '{print $2}' should pull out what's in parenthesis. Prints nothing if it's not there. So... $ who am i | awk -F"[()]" '{print $2}' www.example.com --Christopher Karel


13

awk '{ if (length($0) < 16384) print }' yourfile >your_output_file.txt would print lines shorter than 16 kilobytes, as in your own example. Or if you fancy Perl: perl -nle 'if (length($_) < 16384) { print }' yourfile >your_output_file.txt


12

Use ps Output Formatting: ps -A -o pid Output formatting of the command is the best option. The o option controls the output formatting. I listed some of arguments below below, see 'man ps' for the rest ( to use multiple it would be -o pid,cmd,flags). KEY LONG DESCRIPTION c cmd simple name of executable C pcpu ...


12

I would say that a much better/safer solution would be to restores those files from a clean backup.


12

Use nmap. Important to run it as root so you get the MAC addresses. Example: sudo nmap -sP 192.168.1.0/24 Will scan 192.168.1.1 - 192.168.1.255. Look up CIDR notation on wiki if you're not familiar with this subnet notation. You should be able to get nmap from the repos of any recentish Linux distro, e.g. sudo apt-get install nmap or sudo yum ...


12

I can only assume you were matching on the capital A in April and it no longer works because it's now May. Maybe instead of 'A' you should be using '^'.


10

The different alternatives exist, not because each can do the same thing as the other (although this is true for localized cases, or for full programming languages such as Perl), but rather because they can do different things. sed is not very suitable for processing tabular data, and using pure bash for that is usually more pain than one would like. awk ...


10

find /directory -name '*.users' -exec sed -i -r '/^&?userb$/d' {} \;


10

What the heck people? "my whole site got hacked" = Nuke it from orbit and restore from backup. If you really want to, keep a backup copy and investigate it for evidence of how they got in and how to prevent the same thing from happening again. Do not run anything on the machine; get it offline as quick as possible.


10

echo "121.122.121.111] other characters in logs from sendmail...." | sed 's/].*//' So if you have a file full of lines like that you can do sed 's/].*//' filename


9

Quitting when you're done can speed things up: sed '5555,7777p; 7778q' filename


9

#!/bin/bash while read user do read domain echo $user $domain done usage: cat file | scriptname


9

To improve a little on @Iain's answer, I think you can do it in just one pass like this: #!/bin/sh sed -i '/<\/body/ { r /path/to/file a </body> d }' $1 This searches for </body>, inserts the file into the buffer, appends </body> to the buffer, and then deletes the original </body>, which as Iain correctly pointed ...


9

Use awk as follows: $ echo '*EXTRA File 78223 C:\foo.pdf' | awk '$3 > 1048576 {print $0;}' $ echo '*EXTRA File 78223 C:\foo.pdf' | awk '$3 > 40000 {print $0;}' *EXTRA File 78223 C:\foo.pdf


9

I think this will split the line as you want sed -e 's/\]/\]\n/g' log | sed -e 's/^ *//g' | awk '/^\[/ {print}' First put a newline after each ] then remove any leading spaces and finally print the lines beginning with [. Your input line becomes [Wed Aug 08 11:39:41 2012] [error] [client 155.94.70.224] [line "271"] [id "960020"] [rev "2.2.5"] [msg ...


8

Check to make sure your Outlook isn't helpfully removing line breaks for you (ie the problem isn't Linux, it's Outlook). By default I think it does. It should be telling you this at the top of the view panel.


8

Since you haven't posted an error message I'm just making an educated guess here. Your script does this: # Set new password for user exec expect -f $0 ${1+"$@"} This calls expect with the full path to your script passed as the argument to expect's "-f" option...which means that expect will start executing from the top of your script, not from the "set" ...


8

$ sed '/Z/s/x/0/g' <input_file>


8

This one command will do what you want: grep -o '\[[^]]*\]' inputfile


7

Use tail -n +X filename to print from the Xth line to end of file.


7

How about this? grep 'on line' /var/log/httpd/error_log | cut -d' ' -f6- | sort | uniq -c | sort -nr I.e. Get the right lines from the logfile Chop the date off the front Sort them Aggregate and count the duplicates Sort by number of duplicates


7

You need to eliminate the backticks and change the single quotes to double quotes: #!/bin/sh ip=$1 echo $ip sed -i .bak "\:#start ${ip}:,\:#end ${ip}:d" /usr/local/etc/racoon/racoon.conf Using double quotes will allow the variables to be expanded. The backticks would try to execute the standard output of the command (which there is none in this case). For ...


7

Add a g to your regexp, for global replacement. Otherwise, only the first occurrence will be substituted: sed s/\!//g myfile


6

This could be acheived by running this sed command on your logs: sed -i "s/^\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+, \)*\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\), [0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+ - -/\2 - -/" Some explanations: The general format is s/MATCH PATTERN/REPLACE PATTERN/ The match is done on the string "some IP, " (0 to many times) followed by ...


6

Either of these should work; sed -n 'startnumber,*endnumber*p' awk 'NR>=startnumber&&NR<=endnumber' file Great question by the way ;)


6

find . -type f -print0 | xargs -0 sed -i 's/href=\"1\//href=\"\/1\//g'



Only top voted, non community-wiki answers of a minimum length are eligible