Ubuntu :: Extract Only The Strings After The Comma?
Jun 1, 2010I have a csv file in this format:
Code:
1,characterswithnospace
2,same
4545,characters
I want to extract only the strings after the comma,
I have a csv file in this format:
Code:
1,characterswithnospace
2,same
4545,characters
I want to extract only the strings after the comma,
I have one question.
Assumed I have have a variable $userlist, it has the following contents:
brownj
smithk
smithk2
smithk3
hynesp
hynesp2
leeb
How can I write a bash script that extracts all the strings smithk, smithk2, smithk3, etc from variable $userlist, and assigns these strings to a new variable?
I have a file with no regular way to grep or sed for any regular expression. The wordings, fields, spacings are random. code...
I want to extract character positions 3 to 10 including spaces. code...
I want to search and replace strings in a file with strings in other files/i need to do it with big strings(string1 is big) and i want to use a txt file for this.But this code not working :
View 14 Replies View Relatedi'm trying to get several strings from a single string, separated by comma's.there are comma's that do not separate strings, however, those enclosed in parantheses.an example would be:vt, word1, (word2, word3)word4
exploding by ',' would result in:
[0]=>vt
[1]=>word1
[code]....
I have a fairly long list of data that I am trying to put into a math program (maple) but before I can do that I need to edit the format of the data such that at the end of every 25th line I add a comma. I would prefer a solution that uses vi, but if that's impossible sed would be fine also (or awk).
View 6 Replies View Relatedsometimes there are one, sometime there are two exchanges in this log file. the 100= is the stock exchange- if there are two, they are seperated by a comma. i understand how to escape a comma in a regex, but I am having trouble with combining it.
35=8 39=1 38=1000 32=13 14=754 31=1.11 44=1.1 100=AMEX,ISE
35=8 39=1 38=1000 32=151 14=205 31=1.1 44=1.1 100=AMEX
35=U 39=2 38=1000 32=45 14=184 31=1.1 44=1.1 100=AMEX,ISE
[code]...
I'm trying to compose a line of numbers each single digit taken from a variable eg: 1010001 each variable digit is either a 0 or 1 made from variable layer1 through 7. I need to add each layer variable to the last to compose the number with no commas or spaces and add it directly after the -p option in the show_command line. I used array and list and the commas mess up the command and inserting "pens" in the show command interpertes it literally instead of the list or array value? The insert should look something like 1000110
Code:
need to monitor pecific processes over a time frame in terms of the amount of memory and cpu usage it utilizes. I can do this using the top -p <pid> option and using ps to retrieve the pid's. However, seeing that the pid's might differ and it needs to be run on about 13 different machines, I would like to write a script for this that can be run at set intervals. My problem that I have is this:
- When running top -p <pid> I can specify a comma seperated list of the processes required to monitor at that specific time.
- I can use ps -ef | grep <process> | grep -v grep| awk '{ print $2 }' to retrive the list of pid's and output this to a file.
However, how can I output these to the file as a comma seperated list without having to manually do this every time? The reason for this is (an example), lets say I want to monitor the cpu and memory usage of postgresql as well as all its child processes, then I would ps grep for postgres and get the list of pid's for instance.This list then needs to be passed to top -p as a comma seperated list of pid's I suspect that awk or sed might have some options available for this but I do not know this well enough.
I'm trying to count words in a text file that has a comma as separator. I know that I must user wc -w, but wc uses space as a separator
View 2 Replies View RelatedI have a file of the formcol1, col2, $330,000, col4 ...col1, col2, col3, col4 ..col1, col2, $230,000, col4 ...The comma within the currency value causes the column to display unevenly when I open it so I want to remove it. I think I should be able to use the sed command but I am not sure extactly how. All the values have 3 digits after the $ and before the , so have triedsed -e 's/$[0-9]*,/ but I am not sure how to 'replaced with the string found just without the comma'So two guestions:1. Is this a good way to do it?2. How do I do it
View 8 Replies View RelatedI have a plain text file with 360 lines of varying length text. How do I add a comma or other symbol to the end of each line so that I can convert the file to csv format that I can open in a spreadsheet (45 rows, 8 columns). That means each 8 lines of text forms 8 columns, with 45 rows.
View 9 Replies View RelatedI would like to create csv output from an ipcalc calculation.
Code:
[me@host scripts]$ ./ipcalc 192.168.30.40/255.255.255.248
Address: 192.168.30.40 11000000.10101000.00011110.00101 000
[code]....
I wanted to randomize the comma separated string.String like "test1,test34,test5,test6".And it would be displayed differently when I ran each time.
Expected output like "test5,test6,test1,test34".
I have been searching previous posts but could not find an example which works with my data. I think I might be the spaces in my fields. I have a massive data file and need to join 5 line blocks separated by a comma.
Code:
2
111.222.333.444
host.edu
[code].....
I have a script that output all my data in to a comma-delimited file separated by ";"
Current Output:
Quote:
"SAP 1117A";10.94.1.7;239.234.1.12;0;0;0;0;0;3;172.31.207.45;""
"";NA;239.192.1.50;0;0;0;0;0;3;172.31.207.61;""
"";NA;239.192.1.50;0;0;0;0;0;3;172.31.207.62;""
[code]...
I would like to remove all lines that have an NA in the second field.
New Output
Quote:
"SAP 1117A";10.94.1.7;239.234.1.12;0;0;0;0;0;3;172.31.207.45;""
....
I have a CSV file that's created in an application that can't output lines longer than 250 characters. the data fields, all together, are longer than this. how would I remove the line break from every line that ends with a comma? For example:
A,B,C
D,E,
F
G,H,I
becomes:
A,B,C
D,E,F
G,H,I
I am in the process of learning some scripting, however I am running into a roadblock in specifying a certain time format in the array. Ideally I would like to use Here are the lines of text that I am interrogating:
1123,3/25/2010,00:14 Thu,33229
1124,3/26/2010,13:30 Fri,33230
1125,3/27/2010,04:49 Sat,33231
[code]...
I am using Ubuntu 9.10 in U.S. English with a German keyboard layout. Accordingly, pressing the delete button on the numeric keypad will produce a comma, which most applications do not recognize as a decimal. in order to have the key produce a period.
I have tried editing the /usr/share/X11/xkb/symbols/de and changing the line
Code:
include "kpdl(comma)"
in the "basic" section of the file to
Code:
include "kpdl(period)"
which seemed like the perfect solution, but upon restarting an error message pops up and the keyboard layout is changed to U.S. English.
Code:
cd /usr/share/X11/xkb/symbols
xkbcomp -lhlpR '*' -o ../symbols.dir
which does nothing at all if used with sudo and produces an error message if used without. Reverting changes to /usr/share/X11/xkb/symbols/de removes all errors.
Is there something else I need to do to have xkb accept my changes to the file?
Code:
include "kpdl(comma)"
does not specify a symbol to be mapped to the keypad delete key, but rather constitutes a command that integrates a pre-specified option into the layout file. Thus, simply removing the line works perfectly well, even without using the above suggestion to register the change to the file with xkb (or whatever it does).
localhost is now fine and localhost/test.php too. However php embedded in html files refused to save in /var/www? what is wrong with my server not being able to read .php strings?
View 2 Replies View RelatedI am looking for an application that will read the file names in a folder and generate a comma delimited file. I want then to import the comma delimited file contests to a spread sheet such as open office.I hava a number of PDF files generated from a scanner, each file with its own scaner generated file name. I want to put these into a data base so I can add the title and other reference information to provide a data base.
View 7 Replies View Relatedhere's my newbie question - I want to change the following string in text files
Code:
E:MP3
with the following string using sed:
[code]....
I have two text files in the form:1 ItemA [value]2 ItemB [value]3 ItemC [value]Some of these items are common for both files, while others are missing from either one or the other.I want to compare the values for each common item in the two lists, but don't know how. I have a vague idea that probably grep might be useful, but I don't know how to use it for this purpose.So, to sum it up, what I would like to do is to take to text files containing lists and merge their common items into a third file in the form:
1 ItemA [value_from_list1] [value_from_list2]
2 ItemB [value_from_list1] [value_from_list2]
3 ItemC [value_from_list1] [value_from_list2]
[code]....
I am having a lot of problems trying to change one string by another using sed: the sentence is like this:
sed -i 's/KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0660"/KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0666"/g' 50-udev.rules
it is just to fing the line with:
KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0660"
[code]....
I wrote this small program that will truncate a string that's entered in by the user.An example of its usage:if the user enters in a string say "abcdefghijklmnopqrstuvwxyz" the program will only take the first 9 characters and truncate the rest so that the user can be prompted for a second string and not be worried about remaining characters left in the stream.Now this program works O.K. but I would like to find something in C that has this functionality build into it...Does anyone know of any function that will accomplish this.
View 1 Replies View RelatedI am trying to replace a section of a file between the first instances of the strings {}, with the contents of another file. Example of the format of the file I'm trying to modify
Code:
Servername=something.com
hosts {
macaddress1
macaddress2
[code].....
Then captured all the "macaddress#"s to a variable and used sed to swap
sed "s/$CURRENTDATA/$NEWDATA/" filename
However I get 1 of 2 errors,
Using a small number of macs in "$NEWDATA"
sed: command garbled: s/ macaddresshere
Or when using a large number of macs in the $NEWDATA variable get
bash: /usr/bin/sed: Arg list too long.
how to replace a large block of txt in one file with another large block from another?
I have several CS servers running on ubuntu server, and sometimes someone is trying to brute server's RCON password with the program called HLBrute. I've found the following rules to prevent such hack attacks, but they don't work What can be wrong in these rules?
Quote:
iptables -A INPUT -p udp -m multiport --dport 26000:30000 -m string --algo kmp --string "HLBrute" -m limit --limit 1/hour --limit-burst 5 -j LOG --log-prefix " HLBrute_Ataka "
iptables -A INPUT -p udp -m multiport --dport 26000:30000 -m string --algo kmp --string "HLBrute" -j DROP
I'm not overly great with bash scripting. I do more batch file stuff for Windows than anything else but I'm trying to branch out a bit. (Frankly, I'd love to do this in Ruby but I'm not there yet...) Maybe I'm not using the correct terminology and that's why my searches are coming up useless...
Anyway, I have a script that does some work with HandBrake. Although it deals with HandBrake, I think the issue is not with HandBrake itself. The issue: I had a simpler script which worked fine but it would give me an MP4 with a file name of: Some Movie Name.iso.mp4 and it would still play but I wanted to get rid of the .iso in the file name. I also wanted to drop it into another directory during the encoding. That's why you see a $source & a $destination variable.
handbrake.sh
Code:
#!/bin/bash
source=/media/data/movies
destination=/media/data/movies/mp4s
[Code]...
I use udhcp with some of my minimal installs. I've messed around with the code a bit when it wasn't working correctly - a few years ago. I will find time - I hope soonish - to figure out how to do a few other things with it.
For now though, I'm using this string to grab my ip after startup
Code: Select allsu -c 'ifconfig eth0&&ifdown -a&&ifup lo&&ifup eth0'&&/sbin/ifconfig eth0
I realize I could substitute ifup -a but I'm more interested in figuring out how to make ifup wait for the ip to become available if it is not available yet.
Never mind that one, just typing out the question answered it for me, when I find it in the scripting man ' ; : " & =
Or if there are any other suggestions for better construction of the string.
I have a PHP script written that is checking a string to see if it contains a link in it (i.e. a URL). I have the following if statement, that uses 3 possible regular expressions to determine if there is a link or not.
Code:
// check if we found a link
// links are denoted by strings that:
// - contain http://
// - contain www.*.*
[Code]....
I'm not convinced yet that writing a shell script to do this is the best course of action. If someone is capable of doing this with a Perl or a Python script that's fine too. If you want to make it super high performance and write it in assembly