LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-11-2016, 07:34 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Question Have a sed file I'd like to extract fields from


Here's a sample from the file:

Code:
s/aborigone/native/
s/annoyed/vexed/
s/angry/furious/
s/anxious/nervous/
s/athletic/athlete/
s/cage/caged/
s/canoe/kayak/
s/capture/vidcap/
s/car,/automobile,/
s/carpark,/parking-lot,/
And what I want to do is extract the words in the second and third fields and write them to two text files so I have a "master" set of keywords and supplemental categories for annotating JPEG files.

This file is about three years old, and I've so far this year gone by finding the keywords I recall having a different Supp. Cat., but drawing these out to separate lists (I had them but things go missing or get deleted after two years) would prove a lot easier.

I'm sure it's a simple matter of using tr or awk or something along those lines, But like a lot of other things with scripting, I've forgotten the syntax of those tools.

I leave it to the board's magnanimity.

Carver
 
Old 11-11-2016, 07:44 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
you can try:
awk -F/ '{print $2}'
for example
and read man page of awk if you have forgotten the syntax
 
1 members found this post helpful.
Old 11-11-2016, 07:47 AM   #3
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Code:
cut -d/ -f2 < sourcefile > destfile1
cut -d/ -f3 < sourcefile > destfile2
-d delimiter to use, in this case, '/'
-f field to cut, the second and third, respectively

Last edited by goumba; 11-11-2016 at 07:49 AM.
 
1 members found this post helpful.
Old 12-05-2016, 11:43 AM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Smile Great suggestions, they both work well...

Moving on.

I used to have a script that read the items in field 2 (keywords), matched them with the items in field 3 (supplemental categories), dumped them to a temporary text file, sorted them alphabetically reading from that file, then wrote that string to another text file I could sed into the first file after adding ^ as a delimiter. Another script wrote each item in the strings into JPEG files using Exiftool. I still have the last script, and I'd like to rewrite the "match and sort" one if I could. It would make it much easier to annotate picture files like JPEGs whose metadata containers support "keys and cats," as I've always called them.

Carver
 
Old 12-06-2016, 12:26 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
if you need help or want to discuss any of your scripts please post them (and also try to explain how does that work, what did you try to achieve, what kind of problems you have ...) - here, or in a new thread.
 
Old 12-08-2016, 01:25 PM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
This doesn't help you with your extraction, but just for info it's aborigine, not aborigone.
 
1 members found this post helpful.
  


Reply

Tags
awk, extract, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed use - extract substring from lines of text file tastiero Linux - Newbie 26 03-12-2012 04:10 AM
[SOLVED] Will gawk extract bits of text fields from a few thousand identically structured file taskmaster Linux - Software 4 11-10-2010 08:46 PM
Use awk and sed to extract height and width of file toben Programming 6 08-04-2010 06:16 AM
using sed or grep to extract stuff from a text file DEF. Programming 5 12-12-2009 10:13 AM
Hi,all. I have a configure file. I wanna extract something from it using sed or awt cryincold Programming 4 04-02-2008 03:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration