Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to insert a string and variable at specified position in command in bash? Post 303042141 by rbatte1 on Monday 16th of December 2019 09:55:13 AM
Old 12-16-2019
Do you want something more like:
Code:
printf -- "/path/to/xxx.py \\\\\n%s\n\t--ref /path/to/file \\\\\n\t--run /path/to/data\n" \                       # Set up the output format with fixed strings and an assignment for where the data goes
   "$(for bamfile in *.bam; do printf -- "\t\t--bam %s \\\\\n"    "${bamfile}"; done)"                            # Collect & list the data file lines here, tab indenting each with \t and finishing with the formatting to append the \ and the new-line
                                                                                                                  # This will get used in the above line as the input for the data.

Lots of escaping in the strings which makes it look a bit messy, but it seems to work for me. After creating dummy files as you have, I got the output:-
Code:
/path/to/xxx.py \
		--bam s1.bam \
		--bam s2.bam \
		--bam s3.bam \
		--bam s4.bam \
	--ref /path/to/file \
	--run /path/to/data

Does this do what you need?


Robin

Last edited by rbatte1; 12-17-2019 at 07:07 AM..
These 3 Users Gave Thanks to rbatte1 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

2. Shell Programming and Scripting

search a line and insert string into specific at position

Hi, guys. I have one question: How can I search for a line with certain string in it and then insert a string into this line? For example: There is a file called shadow, the contents of it are below: ************************** ... yuanz:VIRADxMsadfDF/Q:0:0:50:7:::... (9 Replies)
Discussion started by: daikeyang
9 Replies

3. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

4. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Insert charactera in 1st position of specific lines using vi editor or sed command

Dear all, i am having text file like below surya rama ranga laxman rajesh reddy i want add string (OK) before a text from line 3 to 5 the result will be surya rama OK ranga OK laxman OK rajesh reddy (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. Shell Programming and Scripting

Need command or script to print all lines from 2nd position to last but one position

hi guys, i want command or script to display the content of file from 2nd position to last but one position of a file abcdefghdasdasdsd 123,345,678,345,323 434,656,656,656,656 678,878,878,989,545 4565656667,65656 i want to display the same above file without first and... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

8. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

9. UNIX for Beginners Questions & Answers

Bash: Insert in a variable a file

hi all i have a problem in the bash shell. i'd like insert in a variable a file for example : i have a file datafine.log in this file there is : 17/JUN/2019 i want to insert the value of datafine.log in a variable. Regards Frncesco edit by bakunin: please use CODE-tags for your data... (2 Replies)
Discussion started by: Francesco_IT
2 Replies

10. UNIX for Beginners Questions & Answers

How to insert subnode in xml file using xmlstarlet or any other bash command?

I have multiple xml files where i want to update a subnode if the subnode project points to different project or insert a subnode if it doesn't exist using a xmlstarlet or any other command that can be used in a bash script. I have been able to update the subnode project if it doesn't point to... (1 Reply)
Discussion started by: Sekhar419
1 Replies
SURFRAW(1)						      General Commands Manual							SURFRAW(1)

NAME
surfraw - a fast unix command line interface to WWW services SYNOPSIS
surfraw elviname [options] search words ... sr elviname [options] search words ... sr -elvi sr bookmark DESCRIPTION
Surfraw provides a fast unix command line interface to a variety of popular WWW search engines and other artifacts of power. It reclaims google, altavista, dejanews, freshmeat, research index, slashdot and many others from the false-prophet, pox-infested heathen lands of html-forms, placing these wonders where they belong, deep in unix heartland, as god loving extensions to the shell. Surfraw consists of a collection of elvi, each of which knows how to search a specific web site. To see the list of elvi type: surfraw -elvi Note that sr is an alias for surfraw, so that could equally be sr -elvi To search using an elvis use: sr elviname [options] search terms.. For example, to search google for information on Debian ports, using the "I'm feeling lucky" option: sr google -l debian ports Adding the elvi to your path If you are a regular user of surfraw, you will probably get sick of typing sr or surfraw each time. You can regain the old behaviour of running the elvi directly by adding the elvi directory (/usr/lib/surfraw) to your path, either manually or using surfraw-update-path(1). Bookmarks Surfraw supports bookmarks. To add a bookmark, add it to /etc/xdg/surfraw/bookmarks or $HOME/.config/surfraw/bookmarks The format of the bookmarks file is simple, each bookmark is on a separate line, with the bookmark and URL separated by whitespace, eg: ntk http://www.ntk.net/ To invoke a bookmark, use "surfraw bookmark" or "sr bookmark", and if an elvis of that name doesn't exist, it searches for a bookmark of that name instead. There are some example bookmarks in /etc/xdg/surfraw/bookmarks OPTIONS
Use sr elviname -local-help for elvi-specific options. The following options work with all elvi. -help Show summary of options (including elvi-specific options). -local-help Show elvi-specific options. -version Show version of program. -browser=EXECUTABLE Set browser (default: sensible-browser). -elvi Display a list of other Surfraw mechanisms for conquering evil. -escape-url-args=yes|no Apply url escaping to arguments (default: yes) -q|-quote Bracket all arguments with " characters (default: no). Note that putting quotes round arguments works now, so you can do, for exam- ple: sr google foo "bar baz" bam and the quoting is passed on to the search engine EXAMPLES
$ sr ask why is jeeves gay? $ surfraw google -results=100 RMS, GNU, which is sinner, which is sin? $ sr austlii -method=phrase dog like $ /usr/lib/surfraw/rhyme -method=perfect Julian CONFIGURATION
Surfraw uses the XDG basedir spec (http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html) to locate config files. The default locations are shown below, but can be modified by setting the environment variables $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS. See the spec for more details. Surfraw gets its configuration from three sources, in order: 1. Environment variables 2. /etc/xdg/surfraw/conf 3. $HOME/.config/surfraw/conf /etc/xdg/surfraw.conf and $HOME/.config/surfraw/conf are both fragments of bourne-shell style shell script. /etc/xdg/surfraw.conf should use def and defyn to define variables. These functions set variables unless they are already set by the envi- ronment. defyn is used for boolean configuration variables, def for all others. For instance: def SURFRAW_text_browser /usr/bin/lynx defyn SURFRAW_graphical no $HOME/.config/surfraw/conf should use sh-style entries, eg: SURFRAW_text_browser=/usr/bin/lynx SURFRAW_graphical=no This is because you want them to override environment variables unconditionally. CONFIGURATION VARIABLES
SURFRAW_global_conf Location of global configuration file. Default: def SURFRAW_global_conf /etc/xdg/surfraw/conf SURFRAW_conf Location of per-user configuration file. Default: def SURFRAW_conf $HOME/.config/surfraw/conf SURFRAW_graphical Whether to use a graphical browser. Default: defyn SURFRAW_graphical no SURFRAW_text_browser Name/path of text browser executable. e.g. links, lynx, w3m Default: def SURFRAW_text_browser sensible-browser SURFRAW_graphical_browser Name/path of graphical browser executable. e.g mozilla, netscape etc. Default: def SURFRAW_graphical_browser sensible-browser SURFRAW_text_browser_args Text browser arguments, or "none". Default: def SURFRAW_text_browser_args none SURFRAW_graphical_browser_args Graphical browser arguments, or "none". Default: def SURFRAW_graphical_browser_args none SURFRAW_graphical_remote Whether to use "-remote openURL" for graphical browser. Default: defyn SURFRAW_graphical_remote yes SURFRAW_new_window When using SURFRAW_graphical_remote, open a new window? Default: defyn SURFRAW_new_window no SURFRAW_screen Name of screen command to run. Default: def SURFRAW_screen screen SURFRAW_new_screen If surfraw is running under screen(1), start a new screen for each text browser invocation? Default: defyn SURFRAW_new_screen no SURFRAW_screen_args Arguments to pass to the SURFRAW_screen command Default: def SURFRAW_screen_args "" SURFRAW_quote_args Whether to "quote" all the arguments. Default: defyn SURFRAW_quote_args no SURFRAW_quote_ifs Whether to re-quote arguments if they have spaces in, ie so: sr google foo "bar baz" bam works as expected. Default: defyn SURFRAW_quote_ifs yes SURFRAW_results Default number of results to return (not supported by all elvi). Default: def SURFRAW_results 30 SURFRAW_escape_url_args Whether to escape [% "$%&+,/:;<=>?@[{|}~'] characters in command line arguments subsequently used to construct a url. Default: defyn SURFRAW_escape_url_args yes FILES
/usr/lib/surfraw Location of the elvi. ${HOME}/.config/surfraw/elvi Per-user elvi. /etc/xdg/surfraw/conf Default system wide configuration file. $HOME/.config/surfraw/conf Default per-user config file /etc/xdg/surfraw/bookmarks System wide bookmarks file. $HOME/.config/surfraw/bookmarks Per-user bookmarks file. BUGS
Please report any bugs found (or any web sites in need of surfrawizing) either via the debian bug tracking system (http://bugs.debian.org/) or to the surfraw-devel list (surfraw-devel@lists.alioth.debian.org). SEE ALSO
http://alioth.debian.org/projects/surfraw/ PROPAGANDA
Oh Baybe I need some Deep Linking Let us go Surfin' in the raw! Read HACKING. Surfrawize the soul of your favourite internet wonder. Join the Shell Users' Revolutionary Front Against the WWW by submit- ting code. Reclaim heathen lands. Bear witness to the truth. Its love will set you free. Join us on surfraw-devel@lists.alioth.debian.org AUTHORS
Originally written by Julian Assange. Now maintained by the surfraw-devel team <surfraw-devel@lists.alioth.debian.org>. See the file AUTHORS for the full list of contributors. Man page by Ian Beckwith, based on the original README and an earlier man page by Christian Surchi. COPYRIGHT
Copyright (c) 2003-2008 The Surfraw-Devel Team <surfraw-devel@lists.alioth.debian.org> Copyright (c) 2000-2001 Julian Assange <proff@iq.org> Copyright (c) 2001 Australian Institute for Collaborative Research Copyright (c) 2000 Melbourne Institute for Advanced Study The copyright holders listed above assert no rights on this release of the software ``surfraw'' and thereby explicity place this release into the into the public domain. Do what you will. Feb 03, 2004 SURFRAW(1)
All times are GMT -4. The time now is 01:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy