Tag Info

New answers tagged

5

Using grep: mapfile -t var < <(grep -Po '^\s+\K[^ ]+(?= ?\(\d+\),?$)' file.txt) grep -P will use PCRE (Perl Compatible Regular Expression) grep -o will print the matched portion of the line ^\s+\K will match the lines starting with whitespaces and \K will discard the match [^ ]+ will match our desired portion (?= *\(\d+\)) is the zero width ...


2

You can grep only the lines with the fields and use sed to remove everything after the opening parenthesis. The resulting list of words can be used directly to populate the array: var=($(grep input-file ' *[a-zA-Z]\+ \?([0-9]\+)' | sed 's/(.*//')) echo ${var[1]} The regular expression used in grep is: space + *: any number of spaces (including 0) ...


0

All from running man dd in terminal: I can understand that count denotes the number of bytes to compress? What is the use of 'bs'? bs=BYTES read and write up to BYTES bytes at a time count=N copy only N input blocks once I have created the file, how do I exploit ( or extract ) it Right click, extract here? Or use the unzip ...


1

ulimit is a shell builtin, and thus only affects the current shell, and processes started by that shell: $ type ulimit ulimit is a shell builtin From man ulimit: The ulimit utility shall set or report the file-size writing limit imposed on files written by the shell and its child processes (files of any size may be read). Only a process with ...


0

Adding script to Startup Applications helped me. Almost... I had to! change permissions


2

If you're sure the names won't have spaces in them, remove the quotes and use ( ) around the command substitution: prvar=($(awk ... temp1)) The effect: $ prvar=( $(awk '/VARIABLES/,/}/ {gsub("VARIABLES"," "); gsub("}"," "); gsub("{"," ");gsub(","," ");print}' temp1) ) $ echo ${prvar[@]} ${#prvar[@]} cycHostAdapterNumber cycHostAdapterID cycManagerID 3


2

I think your problem in the whitespace(space ,tabs , Enter, whatever...) added to the name of the script. And here obviously you press enter I'll show you in example using terminator in my system: $ '/home/maythux/Documents/ts3client_runscript.sh' Outpout While when running: $ '/home/maythux/Documents/ts3client_runscript.sh > > ' bash: ...


2

You used vovar outside single quotes for the first time, but not the second time: ... awk '/'"$vovar"'/,/}/ {gsub("$vovar"," ") ... If you'd been consistent: $ awk '/'"$vovar"'/,/}/ {gsub("'"$vovar"'"," "); gsub("}",": %s,"); gsub("{"," ");gsub(",",": %s,");print}' foo ciscoFlashCopyStatus : %s: %s,


0

Your ls version is not accepting --color=auto parameter. I think you should upgrade it: sudo apt-get upgrade binutils


1

You can use the tree command. Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below: sudo apt-get install tree


2

Tree is the command that will show you the tree view. sudo apt-get install tree then just type tree from the terminal. And tree -d will list only the directories and no files.


3

Here is a little python script: #!/usr/bin/env python2 with open('/path/to/file.txt') as f: print '"'.join(f.read().split('"')[:2]) + '"' f.read().split('"') will read the whole file as a string and then split it on " to get all the " separated portions As we are interested in only the first two " separated portions, '"'.join(f.read().split('"')[:2]) ...


0

If you already have your qml file on the phone, it's pretty easy. All you have to do is to call qmlscene with an extra argument. Start a connection from your desktop/laptop with phablet-shell. Run qmlscene with --desktop_file_hint, example: $ qmlscene --desktop_file_hint=/usr/share/applications/dialer-app.desktop $HOME/Documents/myfile.qml


2

I'd suggest using a shell here document in this case #!/bin/bash function myfun { cat << EOF | gnuplot -p plot "$1" using $2:$3 EOF } Then myfun sourcefile 1 3


2

I really do not know what kind of script is that one. Where did you find it? .../bash/gnuplot seems that someone is getting really confused. But if you have the file with the data, call it sourcefile, with the structure whatever x-data y-data whatever x-data y-data whatever x-data y-data you can have a scatter plot of column 3 versus column 2 ...


1

If you want to copy the file test.txt in every directory in /tmp/target/ ... create a test environment: mkdir /tmp/target cd /tmp/target mkdir -v {folder1,folder2,folder3} touch test.txt copy it: find * -maxdepth 0 -type d -exec cp -vi test.txt {} \;


2

If your goal is to pass a variable to awk in order to use it within the script, you can use awk with the -v option: hey=$(awk -v MYN=$MYN 'NR==MYN' x)


2

I see your problem, you're using single quotes. They won't allow the Bash variable $MYN to expand. You can complicate things by telling awk a new variable, or because it's so simple, you can just switch to double-quotes: awk "NR==$MYN" x I'd have used sed but I can't see any obvious issues with your logic MYN=4 sed "${MYN}q;d" x >> y It seems ...


0

In addition to previous method you can use setsid: setsid emacs file.txt man setsid setsid - run a program in a new session


4

Here's a shorter awk version: awk '/TRAP-TYPE/,/[[:alpha:]]*"$/ ' $ awk '/TRAP-TYPE/,/[[:alpha:]]*"$/ ' testfile.txt sCellEventTrap-03-28 TRAP-TYPE -- CAC Code: 00 ENTERPRISE compaq VARIABLES { scellNameDateTime, scellSWComponent, scellECode, ...


5

Using Perl: < infile perl -0777 -pe 's/((.*?"){2}).*/$1/s' > outfile -0777: slurps the whole file at once instead of one line at the time -p: places a while (<>) {[...]} loop around the script and prints the processed file -e: reads the script from the arguments Perl command breakdown: s: asserts to perform a substitution /: starts the ...


0

According to ibus-typing-booster official site, there is an entry for ubuntu in "How to install" section, but unfortunate seems not working. But anyway you can download the rpm package and try to convert to deb using alien. Install alien: sudo apt-get install alien Converting the RPM file to a Debian package sudo alien package_file.rpm Installing the ...


1

Looks like it is there under the name lp:ibus-typing-booster.


3

Though many programs dont like very long lines as input, when your data is not huge you can often simplify multi-line matching by first manipulating the data to put it all on one line, doing the match, then restoring the newlines. For example, use tr to replace newline \n by some character not in your data (I used carriage-return `\r'), use sed to change ...


2

Using awk to create an SQL query: find . -type f -maxdepth 1 -exec awk -F_ '{print "INSERT INTO table (service_id, mac_adress) VALUES (\""$1"\",\""$2"\");"}' {} \; Example output: INSERT INTO table (service_id, mac_adress) VALUES ("TBBN027162G", "38d8-2f08-0c40"); INSERT INTO table (service_id, mac_adress) VALUES ("TBBN027605G", "38d8-2f08-1518"); INSERT ...


3

In python In a one- (long-) liner: python3 -c 'data = [l.split("_") for l in open("f").read().splitlines()]; [print("service_id: "+d[0]+",", "mac_address: "+d[1]) for d in data]' where 'f' is the sourcefile, between (double) quotes. Output: service_id: TBBN027162G mac_adrres: 38d8-2f08-0c40 service_id: TBBN027605G mac_adrres: 38d8-2f08-1518 service_id: ...


3

I think you miss something, When you run two commands seperated by ; you can kill the both commands by the CTRL+c. just to be sure try this command: find / -name a ; ls /home Then kill the above commands with CTRL+c, this would kill both processes, you'll not list your home content. I.e, the next command will not run. UPDATE: This also will be valid ...


7

Using awk: awk -v RS='"' -v ORS='"' 'NR==1{print} NR==2{print; printf"\n";exit}' file This sets the record separator to ". So, we want to print the first two records and then we are done. In more detail: -v RS='"' This sets the input record separator to a double quote. -v ORS='"' This sets the out record separator to a double quote. NR==1{print} ...


4

Kill the parent process of job1 with SIGKILL. Show the processes in a process tree, eg. with htop or ps axf and kill the parent process of job1 and not job1 itself. Install htop with sudo apt-get install htop Downvoters, understand the answer before downvoting


0

If you really need a terminal to run emacs, the use the command below emacs file.txt & nohup From man nohup nohup - run a command immune to hangups, with output to a non-tty


2

There's no point in testing if it exists or not, rm -rf already does that for you. If it exists, rm removes it. If it doesn't exist, rm considers the job already done, and just returns with success. #!/usr/bin/env bash rm -rf "$@" Which also means there's not really any point in the script, since you can just run rm -rf /some/dir instead of scriptname ...


2

Simple if statement with rm -rf command #!/bin/bash if [ -e "$1" ];then rm -rf "$1" ; fi


3

Since you mention you solved the problem for your specific situation, below a solution for general purpose. Thanks to xdotool's --sync option, it works pretty reliable in the tests I ran; I could "send" commands to specific terminal windows and it ran perfectly without an exception. How it works in practice The solution exists from a script, which can be ...


1

Late to the party but here's my version with find,exiftool,and sort: find . -exec exiftool -S -t -q -FileName -ImageSize {} + | sort -k2n,2 It's a bit slow, but works. Sample output: $ find Downloads -exec exiftool -S -t -q -FileName -ImageSize {} + | sort -k2n,2 1433695350670.jpg 1600x1000 1433695350670.jpg 1600x1000 1434999385912.jpg 2212x3318 ...


1

You can use parameter expansion and an extended glob to "normalize" the whitespace. # enable extended globs so that +([[:space:]]) matches one or more whitespace shopt -s extglob # replace all occurances of one or more whitespace with a single space prvar=${prvar//+([[:space:]])/ } echo "blah blah blah $prvar blah blah" This allows you to safely quote ...


1

You dont have to quote (") everything in echo. You can have many strings. Simply dont quote prvar: echo "blah blah blah" $prvar In the shell (which is expanding $prvar for you before echo even sees it), spaces inside quotes (") are preserved, but spaces and tabs outside quotes are reduced to one space. eg echo "a b" d e a ...


1

Put the following lines in your ~/.bashrc file. export JAVA_HOME=<path/to/java> <path/to/java> will be something like /usr/java/jdk1.5.0_07/bin/java depending on which version you've installed. You can also set the default java to use by running the below command and selecting the desired options from the list: sudo update-alternatives ...


2

Here's a very simple bash script. Make it executable with chmod +x and add as custom startup application to run this continuously on every login. Since I've mentioned aplay, this should work in command line, not just gui. My current laptop doesn't have sound,so i had to test everything with notify-send . Feel free to adapt the script as necessary. ...


0

TL;DR: it's ok, really What you have there is exactly the response that sudo apt-get install some-software-name gives. It's very common to use apt-get on Ubuntu as an alternative to Software Center, which is a bit slow. I don't understand why you are running some script, when you can just use sudo apt-get install package-name-1 package-name-2 package-name-3 ...


1

If you can download the file outside of Firefox, you can use filetodownload=file-to-download.ext wget http://www.example.org/"$filetodownload" -O "$filetodownload" #"I want to create a directory beside the downloaded file automatically" #You didn't specify a dir name mkdir "$filetodownload" Otherwise, you'll have to monitor the file's download progress ...


0

I wrote a function for this: function begin_install_log() { if [ $# -eq 0 ] then echo "No arguments supplied" HIST_NUM="" else HIST_NUM=$(history|tail -n 1|awk '{ print $1 }') HIST_NUM=$((HIST_NUM + 2)) OUTPUT_FILE=$HOME/environment/ansible/.install_cache/${1} fi } function capture_install_log() { if [ ! $HIST_NUM ] then echo "run ...


0

It should be noted that the airmon-ng command requires root priveleges, which can be gained through sudo: sudo airmon-ng


1

Assuming, your script has the name sound_notifier and it's placed in /usr/bin: sudo chmod +x /usr/bin/sound_notifier Create a script /etc/network/if-up.d/start_sound_notifier sudo nano /etc/network/if-up.d/start_sound_notifier add the code below #!/bin/sh if [ "$METHOD" = loopback ]; then exit 0 fi # Only run from ifup. # if [ "$MODE" != start ]; ...


0

If you really want to... and don't want to download pantheon desktop and it's software: libgranite2 libgtksourceview-3.0-1 libvala-0.26-0-dbg libsratchcore0 Install those .deb packages manually, you will probably end up installing other dependencies of those listed above, google them, it doesn't take so much time. Once I had to do the same, because there ...


1

How about sed : sed -i.bak '/^#/d' /etc/squid/squid.conf The original file will be saved as /etc/squid/squid.conf.bak. If you don't want to save the original file, use: sed -i '/^#/d' /etc/squid/squid.conf Or grep : grep -v '^#' /etc/squid/squid.conf > /etc/squid/squid.conf.bak && mv /etc/squid/squid.conf.bak /etc/squid/squid.conf I will ...


2

Using find, file --mime-type, identify, awk and sort Using file --mime-type we find all images, even without an extension. The one-line at the end of this answer has a problem with newlines in the file name. Therefore here an other version: find . -type f -exec sh -c 'file --brief --mime-type "$0" |\ grep -q ^image/ && identify -format "%[fx:w*h] ...


-1

It's complaining saying the request is impossible and those dependencies won't work on this version of ubuntu. if it's really necessary try installing it with sudo apt-get install -f scratch-text-editor If its possible it will force the package to install. Hope this helps.


3

Create a new file in /usr/share/polkit-1/actions/ sudo nano /usr/share/polkit-1/actions/FlashTool.policy and add the lines below: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> ...


-1

sudo -H is enough to start a graphical application preventing changes to the user's configuration files in ~/, since it sets the running environment's home directory to root's home directory: Exec=sudo -H /home/natasha/FlashTool/FlashTool


-1

You could try a simpler one like this: 11| grep trans.sh -xrwxr-xr-x 1 %root% %root% and it might work fine this way.



Top 50 recent answers are included