Skip to main content

All Questions

Tagged with
1 vote
6 answers
226 views

manipulate ls text output to add path to filenames

I get sometimes files with following ls output format: /etc/cron.d: -rw-r--r-- 1 root root 128 May 15 2020 0hourly -rw------- 1 root root 235 Dec 17 2020 sysstat /etc/cron.daily: -rw------- 1 root ...
André Letterer's user avatar
3 votes
5 answers
3k views

Bash - remove dashes and new-lines before replacing new-lines with spaces

I have a bunch of text files in the following format: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam ...
nath's user avatar
  • 6,074
1 vote
1 answer
255 views

Keep all line breaks except the last one using awk

How do I modify this line below to capture the content between two lines without the trailing line break? interesting="$(awk "NR >= $first_line && NR <= $second_line" $file_path | ...
Andrew Wei's user avatar
1 vote
2 answers
46 views

how do i add the creation of a directory to this cli command

I'm traversing a directory, looking for subdirectories, finding certain files, and copying them someplace else... I'm doing this: for i in `ls ./*/filename`; do cp $i ../test2; done This takes all ...
jaynyc's user avatar
  • 11
0 votes
1 answer
215 views

Bash User Input Search For Who is On Server If Statement Error Too Many Arguments

I am working on an assignment that requires me to accept user input to search for current users on the server and if the user input is online, I need to output the users name. If the user is not ...
codenewbie503's user avatar
1 vote
4 answers
6k views

How do I loop over the lines in STDIN and run a shell command?

I'd like to run a shell command on each line taken from STDIN. In this case, I'd like to run xargs mv. For example, given two lines: mfoo foo mbar bar I'd like to run: xargs mv mfoo foo xargs mv ...
mbigras's user avatar
  • 3,422
1 vote
3 answers
990 views

How do I make a substitution to `$0` but save the old value?

I'm trying to rename all files that start with an "m" to be the same name except with the first character (or "m" in this case) stripped away. My strategy is to: List all the files, with ls Filter ...
mbigras's user avatar
  • 3,422
6 votes
4 answers
78k views

grep all strings that start with a certain char, and finish with another char

I need to grep all strings that start with "[" and finish with a certain string, e.g. "apal". So all chars in between these 2 chars would be shown as well. Given an input such as: [44060]apal223reaea[...
testTester's user avatar
6 votes
6 answers
5k views

Command line method to find repeat-word typos, with line numbers

Updated: Clarify line number requirement, some verbosity reductions From the command line, is there a way to: check a file of English text to find repeat-word typos, along with line numbers where ...
clarity123's user avatar
  • 3,579
5 votes
1 answer
7k views

OSX: Delete all matching certificates by command-line

Using shell script to delete all matching certificates. I found a list of certificates using: security find-certificate -c "certificatename" -a -Z|grep SHA-1|awk '{ print $NF }' Output is like this:...
karim's user avatar
  • 153
3 votes
2 answers
12k views

How to insert bash variables in awk? [duplicate]

How to insert bash variables in awk (for example i need to do in in some for loop - like this: in first iteration use awk to search string by first column, next by second column and so on with using ...
dmgl's user avatar
  • 1,093
3 votes
2 answers
1k views

Assign specific line from a variable to another variable

I would like to take a specific line from a variable to another variable. I tried this but it doesn't work: c="1.apple 2.banna 3.peach" read "Please choose fruit [1-3]:" t a=$c | awk "NR==$t" echo "...
Zion Levi's user avatar
2 votes
2 answers
2k views

Extracting values from a file keyed by multiple keys

Consider a file with key=value pairs, and each key is optionally a concatenation of multiple keys. In other words, many keys can map to one value. The reason behind this is that each key is a ...
h.j.k.'s user avatar
  • 1,273
14 votes
6 answers
121k views

How can I output the difference between 2 files?

My file consists of the the following; roughly: username:username:username:username:username The above line continues to about 600 characters. I use the awk command in order to use it as an ...
Ben's user avatar
  • 315
2 votes
1 answer
2k 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. ...
admirabilis's user avatar
  • 4,782