Skip to content
Advertisement

Tag: cut

Bash script how to display matched words in custom order

The following is the output of the command ads2 cls create However, I’m trying to extract the value of name and state for each node, save them in a variable and display them in the following order: Till now i, with the help of this so much powerful learning site, could extract the values of name and state by executing

Trying to find empty files in other user home directory

I want to search for empty files inside the home directory of the user “adam” for example. Now i don’t know the right path for that user, so I need to get it from /etc/passwd with the following command: Output: /home/adam (for example) Then executing this command to find the empty files. Is it possible to do this with one

Extract all unique URL from log with only POST type of the request

I’ve got a log file with the such type of the records: 41.201.181.27 – [2019-04-06 18:22:02] “GET /images/stands/photo_mois.jpg HTTP/1.1” 304 – “http://example.com/popup.php?choix=mois” “Mozilla/4.0” “-” I’ve got the script for getting all records with unique URLs: cut -f4 -d” < logfile | sort -u How i need to change it for getting unique URLs with only POST type of the request?

Linux split a file in two columns

I have the following file that contains 2 columns : How is possible to split the file in 2 other files, each column in a file like this: File1 File2 Answer Perl 1-liner using (abusing) the fact that print goes to STDOUT, i.e. file descriptor 1, and warn goes to STDERR, i.e. file descriptor 2: You could, of course, just

Linux cut, paste

I have to write a script file to cut the following column and paste it the end of the same row in a new .arff file. I guess the file type doesn’t matter. Current file: The output should be: how can I do this? using a Linux script file? Answer Brief explanation, ^([^,]*) would match the first field which separated

Ubuntu bash script grepping and cutting on first column

I am trying to implement a bash script that will take the piped input and cut the first column and return a total. The difference is that the cut is not from a file, but from the piped input. For example: Basically, in my scenario the first column will always be from the passed input. Example usuage is: data.txt contains:

Convert number from text file

I have a file: id name date 1 paul 23.07 2 john 43.54 3 marie 23.4 4 alan 32.54 5 patrick 32.1 I want to print names that start with “p” and have an odd numbered id My command: grep “^p” filename | cut -d ‘ ‘ -f 2 | …. result: paul patrick Answer Awk can do it all:

Using cut to remove until a delimiter from end

I have a string with many delimiters like : abcd – efgh – foobar.extension (Delimiter ‘-‘) I want to remove the So far, I have done But this does not help as it echo’s I want to be able to keep the inital part before the final delimiter(‘-‘) is found. Answer In bash you can use this built-in string manipulation:

Linux cut pattern from log file

i have json log file but theres not only json i need to cut/remove everything what isnt json, structure looks like this: i tried cut -d command but it doesnt work for me Answer This did the work:

Empty string as a output field seperator for Cut

How can I use cut with –output-delimiter=””? I want to join two columns using cut. I tried the following command. However cat -v shows that there are non printable characters. Specifically “^@”. Any suggestions to how can I overcome this? This is the content of my file 011,IBM,Palmisano,t,t,t 012,INTC,Otellini,t,t,t 013,SAP,Snabe,t,t,t 014,VMW,Maritz,t,t,t 015,ORCL,Ellison,t,t,t 017,RHT,Whitehurst,t,t,t When i run my command I’m seeing

Advertisement