FAQ Database Discussion Community


Bash remove line with zero value

bash,file,cut
I have a file which is 1500 lines long containing cpu values, but somehow there is 0 very second line. Is it possible to remove every second line containing only 0 in a bash command ? 8 0 9 0 10 0 10 0 8 0 9 0 ...

Javascript trim multiline string without cutting words

javascript,regex,string,trim,cut
I'm looking for an answer to trim a string to a certain length of chars without cutting words. I searched the questions and found this: javascript shorten string without cutting words I wanted to use @Hamish s answer with the regex replacement but encountered problems with multiline texts. @Hamish s...

Exclude the last-but-one field [closed]

bash,awk,sed,cut,tr
How to exclude or remove the word before the last word in line: Example: var=1 echo "list $var M" Expected: list 1M ...

Translate cut code to grep regex code for locating and returning up to the first hyphen

regex,command-line,grep,cut
I have a list of filenames similar to the following: NAME - Something something something ANOTHER NAME - More stuff THIRD - This is a title FOURTH - This is a title - With an extra hyphen FIFTH NAME - And some more What I would like is to grab...

cut text file and get the first field bash

grep,sh,cut
i had a problem with using grep, or cut command to get out the files size i have that file : 4096 Feb 15 21:52 f1 0 Feb 15 18:24 f4 6928808 Feb 10 16:59 install_flash_player_11_linux.i386.tar.gz 87 Feb 14 18:43 sc1.sh 281 Feb 14 19:11 sc2.sh 168 Feb 14 21:40...

More robust way of extracting date field from string in shell script

regex,bash,date,cut
I have a string which described the active directory expiration date of my account. I want to use/parse this string and do something when expiration date is coming soon. Now I have a problem extracting the date-part of the complete string. The string is: Password expires 1-4-2015 15:41:05 I want...

Continuous to discrete cut quartile in R from for loop

r,loops,for-loop,cut,quartile
I am trying to create a bunch of columns that are quartile cuts based on multiple columns. For example, dataset[,412:422] <- NA for( i in 50:60){ for(j in 412:422){ dataset[,j] <- cut(dataset[,i], breaks=unique(quantile(dataset[,i],probs=seq(.1,1,by=.1),na.rm=T)), include.lowest=TRUE) } } I want to create new columns 412 to 422 based on the binning of...

Remove e-mail string from the beginning of each row in a file

linux,shell,command-line-interface,cut
I have a file with the following format [email protected] some string with no set width [email protected] another string [email protected] yet another string!! [email protected] shortstring What I want to do is run a bash command that will get this file and remove the email+space from the beginning of EACH row and...

shell script linux,bash : moving files according to name field-1 to the specific path in field-2 using `cut`

linux,bash,shell,cut
I am new in shell, I tried to transfer file in field-1 into specific folder according to specific path in field-3 and I hope you can help me. this is my text file: deleted_files.txt ohdah1.sql 5075 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\ sourcetreeconfig 1066 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\ commit-msg.sample 896 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\ post-receive.sample 552 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\ pre-commit.sample 1704...

Extracting Substring from File Name

string,awk,substring,extract,cut
I have a list of files with the following file name format: [some unknown amount of characters][_d][yyyymmdd][some unknown amount of characters] I want to extract the substring that contains the date (yyyymmdd) which I know will always be proceeded by "_d". So basically I want to extract the first 8...

How to split a branch in two with Git?

git,split,branch,rebase,cut
I've made a feature branch from master and then realize at some point that it will be better to start a new branch from this branch. So, how to split a branch in two at a specific commit ? Let me explain with this little schema: I have this: master...

Batch: Truncate String before saving to variable

string,batch-file,truncate,cut
maybe it's a simple question. I want to make a small batch script that outputs installed, used and free RAM. Used RAM is no problem, I just use for /f "skip=1" %%a in ('wmic os get freephysicalmemory') do ( and it outputs the free RAM in MB. But when I...

How to cut varchar/text before n'th occurence of delimiter? PostgreSQL

sql,postgresql,split,delimiter,cut
I have strings (saved in database as varchar) and I have to cut them just before n'th occurence of delimiter. Example input: String: 'My-Example-Awesome-String' Delimiter: '-' Occurence: 2 Output: My-Example I implemented this function for fast prototype: CREATE OR REPLACE FUNCTION find_position_delimiter(fulltext varchar, delimiter varchar, occurence integer) RETURNS varchar AS...

Cut specific words matching a pattern from a text file

shell,grep,cut
I am trying to extract words from a text file matching a pattern using shell script. For example if a line contains This is a sample text to illustrate my scenario text=info id=2342 Second line to illustrate text=sample id=q2312 I want the output to be like text=info id=2342 text=sample id=q2312...

Bash while loop + cut slow

bash,cut
I am trying to process a file (1.5GB) with a bash loop to iterate each line. I used cut for its simplicity (relative) and ended up with: while read line do echo "$(echo $line | cut -d' ' -f 2-3)" "$(echo $line | cut -d'"' -f 20)" done < TEST.log...

Extract minor version from kernel to bash variable

linux,bash,sed,cut
I am new to bash and writing a script that needs to compare the minor version of the kernel to see if it is greater than or equal to 10, and exit if it is not. Currently I have something like: KERNEL = $(uname -r) declare -i MINOR_VERSION=$(echo $KERNEL |...

Combing multiple variables into a new variable in R

r,if-statement,cut
This is probably very simple for someone but I can't seem to make it work for the life of me. I've tried using cut and ifelse but I get levels without the values I want. Any thoughts would be much appreciated. Here's some fake data: o5<-c(1,0,2,0,0,NA) o6<-c(NA,0,NA,2,0,NA) o7<-c(0,0,NA,2,2,1) ID<-seq(1,6,1) d1<-cbind(ID,o5,o6,o7)...

Extract IPs before string [closed]

linux,bash,awk,cut
I have this text: 111.11.1.111(*)222.22.2.221(mgn)333.33.3.333(srv) 111.11.1.111(*)333.33.3.333(srv)222.22.2.222(mgn) 222.22.2.223(mgn)111.11.1.111(*)333.33.3.333(srv) I only want to know the IP's before (mgn), output: 222.22.2.221 222.22.2.222 222.22.2.223 thanks...

How to change horizontal input to vertical output

unix,grep,cut
I am using UNIX Korn shell. I am trying to create a program in Unix that will search a text file which is shown below: Last Name:First Name:City:State:Class:Semester Enrolled:Year First Enrolled Gilman:Randy:Manhattan:KS:Junior:Spring:2010 Denton:Jacob:Rochester:NY:Senoir:Fall:2009 Goodman:Joshua:Warren:MI:Freshman:Summer:2014 Davidson:Blair:Snohomish:WA:Sophmore:Fall:2013 Anderson:Neo:Seattle:WA:Senoir:Spring:2008 Beckman:John:Ft. Polk:LA:Freshman:Spring:2014 Then take that line and cut it out and display it vertically....

Using cut on stdout with tabs

bash,cut
I have a file which contains one line of text with tabs echo -e "foo\tbar\tfoo2\nx\ty\tz" > file.txt I'd like to get the first column with cut. It works if I do $ cut -f 1 file.txt foo x But if I read it in a bash script while read line...

bug in bash sort with different columns?

bash,sorting,multiple-columns,cut
I am working with a file that contains 3 values, an ID (they happen to be protein ids in case you are curious), a value, and then another value. It is tab delimited, so it looks like this: A2M 0.979569315988908 1 AACS 0.925340159491081 1 AAGAB 0.982296215686199 1 AAK1 0.736903840140103 1...

print last two words of last line

awk,sed,cut
I have a script which returns few lines of output and I am trying to print the last two words of the last line (irrespective of number of lines in the output) $ ./test.sh service is running.. check are getting done status is now open.. the test is passed I...