text-processing

Append the arguments to a script as lines in a file

Append the arguments to a script as lines in a file How do you append $@ or $* , each as a new line to a file? I think I already searched for that before. Adding a new option -i –insert-newline with possible values 1, 2, 3 or Linux, Windows, Mac to echo command should …

Total answers: 1

How to get package version in one command line in bash

How to get package version in one command line in bash I’m trying to get the installed version of systemd in the following command, but it returns all lines contain the keyword "systemd". # dpkg -l | grep " systemd " ii gnome-logs 42.0-1 amd64 viewer for the systemd journal ii libsystemd0:amd64 249.11-0ubuntu3.12 amd64 systemd …

Total answers: 1

Add t to jq resulted array extraction

Add t to jq resulted array extraction I want to add t before each element in the resulting jq array and this is for formatting purposes as the result will get added to a file. here is the json file: { "array": ["element1", "element2"] } When you read this array with jq content=$(jq ‘.array’ file) …

Total answers: 1

How can I replace the last occurrence of " before ] (text-manipulation)

How can I replace the last occurrence of " before ] (text-manipulation) I’m doing some text manipulation and I want to replace the last occurrence of " (with ", "four") before ] which could be in different lines. (this essentially adds a new item in the array) e.g: array = ["one", "two", "three"] other_array = …

Total answers: 5

How to only print odd characters of a string in terminal?

How to only print odd characters of a string in terminal? Let’s say I have a file with content "hheelllloo" and I want to clean it up and get "hello", how do I do this in bash? echo "hheelllloo" | <?> Asked By: d9ngle || Source One quick way is to take pairs of characters …

Total answers: 5

fastest way to repeat a list

fastest way to repeat a list I need do some speed test on my Linux commands. The input data is a list of words. For example: $ cat list elephant horse raven cat dog fish For a reasonable speed test I need to have a much larger file. What is the fastest way to repeat …

Total answers: 6

How to remove double quotes within the double-quoted field values in .dat file

How to remove double quotes within the double-quoted field values in .dat file I have a text file that has around 15 columns.  The fields are separated by comma.  One column that is description is double-quoted and also has some words which are double-quoted.  I need to retain the beginning and ending double quotes and remove only the inner …

Total answers: 5

jq: Printing multiple values from multiple arrays at once

jq: Printing multiple values from multiple arrays at once The default functionality of jq is to send each object from an array one at a time, though the join operator can merge those values. My problem is in trying to print all the values from multiple arrays at once. Taking this example: { "key1": { …

Total answers: 2

Replacing variable correctly in alias function

Replacing variable correctly in alias function I’m trying to create an alias function to remove inputted line from file: function remove_line(){ line_to_remove="’s/^"$1"$//g’" sed -i $(line_to_remove) my_file } For example: remove_line domain.com should remove this domain from a given file. However it seems that the $ is not interpreted correctly. What am I doing wrong? Asked …

Total answers: 1

Is it possible to sort the letters in a word in a line of text?

Is it possible to sort the letters in a word in a line of text? So I have a file full of test commands that I like to run against some of my functions to make sure they are handling all possible situations correctly. No point in having duplicate commands tho. Here’s some examples: rap …

Total answers: 5

Error in command su

Error in command su I am creating a command that will change a certain line in the /etc/profile file from a script, however in certain versions of Linux the sudo command may not be activated so it would be necessary to use the su command for this, within the script when executing: Inside the /etc/profile …

Total answers: 1

How can I use $0 in Makefile?

How can I use $0 in Makefile? I would like to include the following command (taken from here) in a Makefile. A simple version of my Makefile script containing the command is: copy_files: sed ‘s/^/./’ ./input_file | rev | LC_ALL=C sort -u | awk ‘p == "" || substr($0,1,length(p)) != p { print $0; p …

Total answers: 1

Display occurrences and count lines between them and after the last one

Display occurrences and count lines between them and after the last one I have this file: table_01 (id, field01, field02, field03, field04) record_01 record_02 record_03 table_02 (id, field01, field02, field03) record_01 table_03 (id, field01, field02, field03, field04) record_01 record_02 table_04 (id, field01, field02, field03, field04, field04) record_01 table_05 (id, field01, field02, field03, field04) record_01 record_02 …

Total answers: 4

How to remove embedded newlines from CSV fields

How to remove embedded newlines from CSV fields I am struggling with processing a file. Normally I should have a line for each host definition. But sometimes, someone split some fields on different lines. Here is an example: "host1","host1","linux server","" "host2","host2","linux server","" Now I would like to find a way (better in bash) to fix …

Total answers: 7

Playing random videos on one's system; minor improvement to include DVDs

Playing random videos on one's system; minor improvement to include DVDs In my .bashrc I have a function which I use to play random videos (not written below, just fyi), and another one for all media files, e.g.: createmediafiles() { find ~+ -type f -iregex ‘.*.(mp3|wav|ogg|flac|mp4|mov|avi)’ > ~/mediafiles.txt find ~+ -type d -name VIDEO_TS >> …

Total answers: 1

How to let sed un-comment one of multiple paragraphs separated by newlines?

How to let sed un-comment one of multiple paragraphs separated by newlines? Clarification: Using GNU sed. Status quo – ~/.screenrc, last lines: # name synthpop # screen -t script emacs -nw /home/$USER/bin/synthpop # name thrashmetal # screen -t script emacs -nw /home/$USER/bin/thrashmetal # number 1 # split -v # focus # chdir "/home/$USER/thrashmetal/src" # screen …

Total answers: 5

Remove all words that appear n+ times without deleting the lines or change the file order

Remove all words that appear n+ times without deleting the lines or change the file order I have a text file that consists of sections, each with two header lines and a body line consisting of space-separated words. An example looks as follows: Shares for DED-SHD-ED-1: [— Listable Shares —] backup backup2 Shares for DED-SHD-ED-2: …

Total answers: 2

Strip filesize from rclone file list

Strip filesize from rclone file list I use rclone and I want to have the file list without the size of the files mention. I can’t find how to do this in rclone so I thought of stripping it with awk or something like that. My output looks like this 59183070 fileserver/transfer_kimberly_2022-12-18_0558 (1).zip 3690 fileserver/transfer_kimberly_2022-12-18_0558 …

Total answers: 3