text-processing

Print csv columns according to user input

Print csv columns according to user input I have a .csv file with multiple lines with the following format: ¬Country¬,¬Year¬,¬Singer¬,¬Song Title¬ ¬Japan¬,¬1999¬,¬Utada Hikaru¬,¬First Love¬ ¬South Korea¬,¬1999¬,¬Lee Jung Hyun¬,¬Wa¬ … I can print the information I want with awk. For example awk -F’¬’ ‘{print $2" – "$4}’ Model.csv | tail -n +2 which will result in: …

Total answers: 1

how to omit/ignore/remove lines starting with local/ using awk

how to omit/ignore/remove lines starting with local/ using awk Variable _RESULT contains an output of pacinfo –verbose local/jre. Using awk script (by Ed Morton – thanks to him!): awk ‘{ match($0,/:[[:space:]]*/) nextTag = substr($0,1,RSTART-1) if ( nextTag != tag ) { if ( NR > 1 ) { prt() } numVals = 0 tag = …

Total answers: 1

How to modify a part of an output of pacinfo in bash?

How to modify a part of an output of pacinfo in bash? Having an example output of pacinfo local/puddletag like this: Name: puddletag Base: puddletag Repository: local Version: 2.3.0-2 Description: An audio tag editor for GNU/Linux Architecture: any URL: https://docs.puddletag.net/ Licenses: GPL-3.0-or-later Groups: modified Requires: python-certifi Requires: python-charset-normalizer Requires: python-configobj Requires: python-distro Requires: python-idna Requires: …

Total answers: 1

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