# Parsing text from one line with shell scripts

**URL:** https://community.unix.com/t/parsing-text-from-one-line-with-shell-scripts/176717
**Category:** UNIX for Dummies Questions & Answers
**Created:** [October 17, 2007, 11:45am UTC](https://community.unix.com/t/parsing-text-from-one-line-with-shell-scripts/176717 "2007-10-17T11:45:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)
#### Post date: [October 17, 2007, 11:45am UTC](https://community.unix.com/t/parsing-text-from-one-line-with-shell-scripts/176717/1 "2007-10-17T11:45:23Z")

</div>

Hi Gurus!

I wonder if anyone can help me, I'm sure you guys can.

I have a text file which contains a lot of data on the one line as follows:

```nohighlight

$[{"_field0":"blah","_field1":"blah","_field2":"blah","_field3":"blah","field4":"blah","field5":blah,"field5":blah},{"html":1,"type":"bingo","bingo":"Results <span class='b'>1<\/span>-<span class='b'>50<\/span> of <span class='b'>497<\/span> for <span class='b'>match<\/span>"},{"id":"2549425,12087370,6013917","ids":62,"type":"record","name":"blah - smashing"},{"id":"4736260,7981901,5614559","ids":52,"type":"record","name":"blah - sorry"}

```

What I need to do is pull all of those id values out (eg 2549425) and write them to a list in a text file.

Any help would be greatly appreciated! 😕

th3g0bl1n

---

<div class="post-metadata">

### Author: ![matrixmadhan](https://community.unix.com/letter_avatar/matrixmadhan/32/5_5575768a8748004e209b776fc1b2916d.png) [@matrixmadhan](https://community.unix.com/u/matrixmadhan)
#### Post date: [October 17, 2007, 2:24pm UTC](https://community.unix.com/t/parsing-text-from-one-line-with-shell-scripts/176717/2 "2007-10-17T14:24:41Z")

</div>

Is that only those values that follow id or values that follow ids as well ?

here is a sample

```nohighlight
sed 's/^.*\"id\":\"//g;s/\".*$//' filename > output

```

---

<div class="post-metadata">

### Author: ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)
#### Post date: [October 19, 2007, 5:44am UTC](https://community.unix.com/t/parsing-text-from-one-line-with-shell-scripts/176717/3 "2007-10-19T05:44:20Z")

</div>

Thanks matrix,

That worked, I'm also looking to extract the 'blah - smashing' and 'blah - sorry' into a list format;

blah - smashing  
blah - sorry

I guess I can tinker with what you've provided to achieve that.

Thanks again,

g0bl1n

---

<div class="post-metadata">

### Author: ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)
#### Post date: [October 19, 2007, 5:49am UTC](https://community.unix.com/t/parsing-text-from-one-line-with-shell-scripts/176717/4 "2007-10-19T05:49:46Z")

</div>

This is what I have;

```nohighlight

sed 's/^.*\"name\":\"//g;s/\".*$//' input > output

```

but this only outputs the last line, e.g.

blash - sorry

Any ideas how I can get it to read the whole line? Perhaps I need to break it up first?

G0bl1n
