cherdt
  • Member for 7 years, 2 months
  • Last seen this week
3 answers
20 votes
209k views
How to find lines containing a string and then printing those specific lines and something else
20 votes

If I am understanding the question correctly, you can accomplish this with one grep command. For Q1a, your grep output can suppress the filename using -h, e.g.: grep -hnr "the_string" /media/slowly/...

View answer
2 answers
1 votes
390 views
Reverse characters in alphabet
10 votes

The rev command will reverse strings: echo ABCDEFGHIJKLMNOPQRSTUVWXYZ | rev produces output ZYXWVUTSRQPONMLKJIHGFEDCBA

View answer
2 answers
7 votes
5k views
~/.bash_aliases vs alias command
Accepted answer
10 votes

Your first method will add it to .bash_aliases, which means the alias will be loaded every time you log in. Your second method adds the alias temporarily, but it will not persist beyond your session. ...

View answer
2 answers
1 votes
2k views
Count unique lines only to a set pattern
Accepted answer
5 votes

cut -f1 -d'-' inputfile | sort | uniq -c cut -f1 -d'-' will treat the file as dash-delimited and return only the first column in each line. sort is necessary for uniq to work properly. uniq -c ...

View answer
5 answers
3 votes
813 views
How to separate output records by ',' while avoiding the trailing comma in awk
3 votes

A non-awk anwser, assuming the problem is as simple as described: paste -s -d',' input_file -s, --serial indicates that it will process the file(s) sequentially (paste is often used to merge lines ...

View answer
4 answers
3 votes
272 views
Copying a file onto several other files with different names
3 votes

Here's a one-liner that would create the files in your example: for i in {2..70}; do cp file1.xyz file$i.xyz; done

View answer
2 answers
1 votes
593 views
What happened after sudo -s
3 votes

-s without a command runs an interactive shell, so you would no longer be in the same shell as the script. See man sudo for details. This should work though: #!/bin/bash example() { echo "Code ...

View answer
3 answers
3 votes
654 views
Generate four random words from a list for XKCD-like passwords
3 votes

It sounds like you're not against non-Perl solutions, you just want something that works on most systems. In that case, the following uses only GNU core utils: sort -R --random-source=/dev/urandom ...

View answer
1 answers
0 votes
37 views
Does ssh use the ssh-agent?
Accepted answer
2 votes

ssh by default will check for certain identity files, for example ~/.ssh/id_rsa. However, you can specify alternative identity files with -i. See man ssh for details. ssh-agent helps manage identity ...

View answer
3 answers
1 votes
66 views
Using file content as arguments multiple times
Accepted answer
2 votes

In a limited test, this worked for me: cat list.txt | xargs cat | xargs rm Since you are using this to delete files, you might want to test it with a non-destructive command first, e.g. cat list....

View answer
1 answers
2 votes
528 views
ffmpeg mass transcode videos in directory
Accepted answer
2 votes

You can process every file in a directory using the find command with the -execdir flag. Example: find /home/videos/unprocessed -type f \ -execdir ffmpeg -i '{}' -f mp4 -vcodec libx264 -preset ...

View answer
1 answers
0 votes
4k views
How do I create a service on CentOS running as a different user than root?
Accepted answer
2 votes

You can specify the user and group under the [Service] heading: User=rails Group=rails See the credentials section of systemd.exec for details. Also, use /etc/systemd/system/myservice.service as ...

View answer
2 answers
2 votes
1k views
Firewall ipfw in FreeBSD
2 votes

You can confirm whether or not machine 2 is receiving and responding to ICMP packets using tcpdump, e.g.: sudo tcpdump -i eth0 icmp In the case you have described, ping would not be successful ...

View answer
1 answers
1 votes
225 views
Apache name-based virtual hosts configured, but both hostnames direct to the same site
Accepted answer
2 votes

It appears to me that the NOIP service is calling your server via a frame, and the frame source is your server's IP address, rather than a domain name: <frame src="http://68.101.98.197:8080" name="...

View answer
2 answers
0 votes
56 views
How to search for a line before a pattern using sed or grep
1 votes

Here's a sed version with xargs: sed -n '/^SQL> @/{s/^SQL> @//;h};/^ORA-/{g;p;}' output.log | xargs -L1 basename -n suppresses default output, so only lines with an explicit print command will ...

View answer
1 answers
3 votes
2k views
How to keep password aging but disable password "inactive"?
Accepted answer
1 votes

The default is set in /etc/default/useradd, e.g.: INACTIVE=-1 See man useradd for details. Note that this will change the default for new accounts, but will not affect existing accounts. You will ...

View answer
4 answers
1 votes
111 views
Print string if present in two separate columns
1 votes

You can use comm to compare 2 files, so first generate a sorted file for each column: cat filename | cut -f1 | sort > column1 cat filename | cut -f2 | sort > column2 Then suppress the first 2 ...

View answer
4 answers
0 votes
71 views
Stripping characters from a string
1 votes

MYVAR=`sed -E 's/[0-9]+.([0-9]+)/\1/g' stringfile`

View answer
1 answers
0 votes
1k views
Getting "command not found" when trying to run rvm command as sudo
Accepted answer
1 votes

Try sudo -E rvm reinstall ruby-2.4.0. From man sudo: -E, --preserve-env Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy ...

View answer
3 answers
0 votes
7k views
How to add comma after each column?
Accepted answer
1 votes

The input file appears to be in fixed-width format. You should be able to open this in Excel and specify the location of each column without any modification. However, since it appears that all of ...

View answer
1 answers
0 votes
2k views
Does the unix Curl command cache pages?
1 votes

cURL does cache SSL sessions. You could try reproducing the behavior but calling cURL with --no-sessionid to see if you get a different result.

View answer
1 answers
-1 votes
41 views
How to count how many times a word is in the start and in the end?
Accepted answer
0 votes

You can use the -c flag with grep to do this. For example, if your input file is words: grep -c '^gg\b' words will show the number of lines where gg appears at the start of the line. grep -c '\bgg$' ...

View answer
3 answers
1 votes
62 views
Grep for specific number of characters after a matching pattern
0 votes

The other answers may suit your purpose just as well, but assuming you want to make sure you match /sw[0-9]{3}$/ only in the first field of the line, you can use awk: awk '$1 ~ /sw[0-9]{3}$/' ...

View answer
1 answers
1 votes
2k views
can't change value in smp_affinity
0 votes

The device on IRQ 51 likely does not support IO-APIC. You can check this by running: cat /proc/interrupts I've provided some (edited) sample output below: CPU0 CPU1 CPU2 ...

View answer
1 answers
2 votes
591 views
Pipe nohup output to logger w/ different priorities
0 votes

You're redirecting the output of nohup to logger. To redirect the output of ls (or your python script), you can use command substitution: nohup sh -c $(ls /tmp 1> >(logger --priority user....

View answer
3 answers
1 votes
619 views
Make statistic of bigrams
Accepted answer
0 votes

paste -d' ' - - < TEXTEN1.txt To get a count of the bigrams produced: paste -d' ' - - < TEXTEN1.txt | sort | uniq -c However, this method is going to exclude half the bigrams. For example, if ...

View answer
2 answers
-12 votes
129 views
Replace a line in a text file but only where it is preceded by a specific multi-line pattern
0 votes

One possible solution: paste -d' ' -s myfile \ | sed 's/\(Orange Apple Banana\) Rice/\1 Olive/g' \ | tr ' ' '\n' Explanation: paste -d' ' -s myfile takes each line of myfile and pastes it ...

View answer
3 answers
-3 votes
85 views
printing the output three times
0 votes

Using cat is not necessary in this case: paste -d' ' File1 File1 File1 -d specifies the delimiter, in this case a space character. If you really want to use cat though: cat File1 File1 File1 | ...

View answer
1 answers
1 votes
137 views
How to replace different text on a single line from a csv?
Accepted answer
0 votes

Here's one way to do it, using Bash: #!/bin/bash # read the line to act upon line=$(head -n 1 $1) while read substitution do # get the first field, delimited by a comma findvar=`echo $...

View answer
3 answers
6 votes
20k views
Counting the characters of each line with wc
-1 votes

You can iterate over the output lines and run wc for each: echo -e foo\\nbar\\nbazz | \ grep -i ba | \ while read LINE; do echo $LINE | wc -m; done If you don't want to count the newline characters, ...

View answer