Clipboard transformation scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Clipboard transformation scripting
# 1  
Old 04-10-2011
Power Clipboard transformation scripting

Hello all,

I've done a bit of clipboard transformation scripting using xclip before, piping contents with " xclip -o -selection clipboard " to grep, sed, awk, then back into the clipboard with " xclip -i -selection clipboard " ... but I am not a fantastically skilled user of either of the three commands, more of a hack. I'm stumped on this one.

Most of my usage requires scraping clipboard contents and reformatting data for pasting quickly without an intermediary step (such as scraping 3500 lines of html and parsing out 95 links to put into a trouble ticket). This is no different, though it's much less data and just needs to be sorted out to one line for frequent, repetitive pasting.

I have a chunk of text that looks like this:

Code:
Customer:         Bobby's Little Widgets, Inc. - 90210 
Ticket Number:    [ChumWorks#: 095959588]
Client:           bobswid-app01

The customer could be any combination of numbers, letters, spaces and symbols of any length, but will always be followed by a hyphen (used in the output) The 5digit number is of no consequence. The Client can be any combination as well, but never contains spaces.

I need to copy one chunk of that, and return a single line that looks like this for pasting:

Code:
[ChumWorks#: 095959588] Partial Backup - Bobby's Little Widgets, Inc. - [bobswid-app01]

I would love to do it with xclip / sed (as I'm REALLY green with awk) but whatever gets the job done is what I'll use, and work to understand why it functions properly.
# 2  
Old 04-10-2011
Hello, la2ar0:

Code:
sed -n '
/Customer:[[:blank:]]*/ { s//Partial Backup - /; s/-[^-]*$/-/; h; };
/Ticket Number:[[:blank:]]*/ { s///; G; h;};
/Client:[[:blank:]]*/ { s///; s/.*/[&]/; H; g; y/\n/ /; p; q; }'

Welcome to the forum,
Alister

Last edited by alister; 04-10-2011 at 11:25 AM.. Reason: Forgot brackets around client
This User Gave Thanks to alister For This Post:
# 3  
Old 04-10-2011
Computer

That was astoundingly fast and unexpectedly clean, thank you! With all the swapping in and out of hold space though, I'm not sure how to put the brackets around the pattern at the end so it looks as follows:

Code:
[bobswid-app01]

Idea? I did study the sed arguments you used, very nice!
# 4  
Old 04-10-2011
Quote:
Originally Posted by la2ar0
That was astoundingly fast and unexpectedly clean, thank you! With all the swapping in and out of hold space though, I'm not sure how to put the brackets around the pattern at the end so it looks as follows:

Code:
[bobswid-app01]

Idea? I did study the sed arguments you used, very nice!
Woops. Forgot that bit. I just edited the post. Try it now.

Regards,
Alister
# 5  
Old 04-10-2011
Well, that just saved me a whole lot of clicking every night. Smilie I think I'll enjoy learning and sharing here.

Here's a cool little grep / sed bit I wrote (with help) to scrape from a massive block of code just exactly the custom linked information I need to paste - it's very efficient and probably easily portable to any source scraping / aggregating usage.

Code:
xclip -o -selection clipboard | grep -oE 'ticketid=([0-9]*)' | sed 's/ticketid=/ tix:/g' | while read LINE; do echo '' $LINE ' ';done | xclip -i -selection clipboard

A bit pedestrian perhaps, but lots of useful things get around on two legs.

Thanks again!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Data transformation

I do have an input text file of the following format with 1000's of lines input file: 3386(11:11,Ani:0,Bri:1,ch:1,Jwe:0,Jor:0,LP:0,Lo:0,NS:1,al:1,bo:0,boy:0,bru:0,sh:0,cor:1,dum:0,ery:0,mac:0,mic:0)... (3 Replies)
Discussion started by: Kanja
3 Replies

2. Shell Programming and Scripting

Row to Column transformation

Hello Experts, I need to transform rows into column using awk. I tried few things but failed to obtain desired output, as I'm fairly new to awk. i/p file 100, READ, 12 100, WRITE, 8 100, SEEK, 1 142, READ, 2 142, WRITE, 34 142, SEEK, 3 O/p Needed PROC_ID 100 142 READ 12 ... (2 Replies)
Discussion started by: sybadm
2 Replies

3. Shell Programming and Scripting

XML file transformation

Hi all, I have to transform a XML file like this: <?xml version="1.0"?> <vocabulary> <voc_id>102</voc_id> <name>Vocabulary Name</name> <description>Voc description</description> <relations>3</relations> <hierarchy>5</hierarchy> <word> <word_id>1</word_id> ... (1 Reply)
Discussion started by: aLittleBeat
1 Replies

4. UNIX for Advanced & Expert Users

Need help in xslt transformation

Hi I have one input xml file <param name="EXTR_COL" valueDesc="AUTHD_RFLL" value="rx.AUTHD_RFLL" /> There is a mapping parameters in Database. if EXTR_COL is present in input XML then it is mapped to fieldlist. so the o/p XML looks like <fieldlist> <datasource... (1 Reply)
Discussion started by: srinu19
1 Replies

5. Shell Programming and Scripting

xslt transformation through Unix

Hi .. I have one input XML and I want to convert into another XML using parameter mapping through Database through Unix shell script. But I dont have idea how to do that. And how can I create xsl sheet if mapping is through database tables. Please help me on this. (1 Reply)
Discussion started by: srinu19
1 Replies

6. Shell Programming and Scripting

XML to csv transformation

Hi, I want to write a perl script. Which should accept the xml file, one xsl file and the loaction. The perl script should process the xml file using the xsl file and puts the out put in specified location. For example: My.perl is perls cript. my.xml is like this <?xml version="1.0"... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

7. Shell Programming and Scripting

file name transformation

I've got a multitude of text data files that carry exactly the same kind of data. Unfortunately some of them have a different filename format some are: 'category'_'month'-'year'_act.txt an example being: daf_Apr-1961_act.txt and some are: 'category'_ 'year'-'month'_act.txt an... (16 Replies)
Discussion started by: vrms
16 Replies

8. UNIX for Dummies Questions & Answers

Reflection X clipboard issues

Hey, Has anyone else ever run into a problem with Reflection X and clipboard not working? I'll copy something command line, try to vi into a file and paste it and it either pastes nothing or sometimes the correct data and even in some cases it will print stuff in the clipboard from 3 copies ago.... (2 Replies)
Discussion started by: kingdbag
2 Replies

9. UNIX for Dummies Questions & Answers

Transformation capital letter

:confused: Hye everybody i would like to know if exist a internet site where i can founs some interesting shell script very usefull I need to transform hundreds names of files escribed in CAPITAL letter in minuscule letter do oyu know a mean o do that that thanks to a script or a shell... (1 Reply)
Discussion started by: Dark Angel
1 Replies
Login or Register to Ask a Question