New answers tagged

2

You can do this with find alone using the -exec action: find /location -size 1033c -exec cat {} + {} will be expanded to the files found and + will enable us to read as many arguments as possible per invocation of cat, as cat can take multiple arguments. If your find does not have the + extension or you want to read the files one by one: find /location -...


1

The command should be kill -2 %2 with proper spacing. The % sign at the beginning of your line is probably just the prompt they are using (PS1).


5

@steeldriver's comment is correct: cat shows line-endings with $ (as vi might if you asked it nicely, using ":set list"). The extra character per line is the newline (an invisible character at the end of each line of text). If you want only a count of the printable text, you could filter the file before processing it with wc, e.g., using tr with the -d ...


1

POSIX Awk; this works with an arbitrary amount of files, and the files don’t even have to have the same amount of lines. The script keeps going until all files are out of lines: BEGIN { do { br = ch = 0 while (++ch < ARGC) if (getline < ARGV[ch]) { printf ch < ARGC - 1 ? $0 FS : $0 RS br = 1 } } while (br) }


2

tr is a command that does a character-by-character translation. e.g the following command will change the character e to an E $ echo hello | tr 'e' 'E' hEllo When you use 2016-05-25 you're telling the tr command to switch the characters 2 and 0 and 1 and the range 6-0... which is where it gets confused. The command you really want to use is sed: $ sed '...


1

What about command argument --parameter=$(tr '\n' ',' < params.txt)


3

Let's look at this command from the question: command argument --parameter=$(cat params.txt) | tr " " "," This runs the command command argument --parameter=$(cat params.txt) and pipes its output to tr " " ",". That is not what you needed. Try: command argument --parameter="$(echo $(cat params.txt) | tr " " "," )" Here, echo $(cat params.txt) causes ...


2

Redirections are set up by the current shell, so sudo has no effect on your ability to write in /etc/udev/rules.d. The usual trick for this is to use tee: sudo tee /etc/udev/rules.d/69-libmtp.rules < /tmp/1 As pointed out by infixed though, in this particular case you don't need a redirection: sudo cp /tmp/1 /etc/udev/rules.d/69-libmtp.rules


0

Once you have a file containing times in the form 1m59.973s (eg. the output from Mikael Kjær's answer), you can transform them into a single sum for bc(1): ( cat alltimes.log | sed 's_h_*3600+_;s_m_*60+_;s_s_+_' | tr -d '\n' ; echo 0 ) | bc That prints a number of seconds (including decimal places). Then bash (whose arithmetic expansion doesn't handle ...


0

As others have shown you, there is no need to use cat -n. Other programs will do it for you. If, however, you really need to parse the output of cat -n and show only specific lines (for example, 4-8, 12 and 42), you could do: $ cat -n file | awk '$1>=4 && $1<=8 || $1==12 || $1==42' 4 Line 4 5 Line 5 6 Line 6 7 Line 7 8 Line 8 12 ...


0

Depending on goals I like head or grep cat /var/log/syslog -n | head -n 50 | tail -n 10 will return lines 41 thru 50. or cat /var/log/syslog -n | grep " 50" -b10 -a10 will show lines 40 thru 60. The problem with the grep method is that you have to use account for padding of the line numbers (notice the space) Both are quite handy for parsing log files....


14

Use sed Usage $ cat file Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 To print one line (5) $ sed -n 5p file Line 5 To print multiple lines (5 & 8) $ sed -n -e 5p -e 8p file Line 5 Line 8 To print specific range (5 - 8) $ sed -n 5,8p file Line 5 Line 6 Line 7 Line 8 To print range with other specific line (5 - 8 &...


10

One way of doing it is by using sed: cat -n text.txt | sed '11d' where 11 is the number of the line you want removed. Or to remove all but 11: cat -n text.txt | sed '11!d' Ranges are also possible: cat -n text.txt | sed '9,12!d' And cat -n isn't even needed: sed '9,12!d' text.txt


2

Actually � is not a "nonsensical character". That is the Unicode replacement character. It is displayed in a terminal using UTF-8 encoding when attempting to display a byte which is not a legal UTF-8 code. It may be displayed (but far less likely) when the fonts available for the terminal do not provide a particular legal Unicode value, but it's more ...



Top 50 recent answers are included