Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Print strings in bash in loop Post 303042343 by 7adi on Sunday 22nd of December 2019 06:37:26 AM
Old 12-22-2019
Print strings in bash in loop

Hello All,


I am a newbie and have been struggling to print in loop.


I have one line hold in a variable and need to print them with first six strings.



We have get the value with below macOS terminal command.



Code:
osascript -e 'tell application "System Events" to get properties of every login item'


Quote:
name:Pages, path:/Applications/Pages.app, class:login item, kind:Application, hidden:false, name:Calculator, path:/System/Applications/Calculator.app, class:login item, kind:Application, hidden:true, name:Calendar, path:/System/Applications/Calendar.app, class:login item, kind:Application, hidden:false

need to print them with new line like below:



Quote:
name:Pages, path:/Applications/Pages.app, class:login item, kind:Application, hidden:false


name:Calculator, path:/System/Applications/Calculator.app, class:login item, kind:Application, hidden:true


name:Calendar, path:/System/Applications/Calendar.app, class:login item, kind:Application, hidden:false

I know i did wrong but i use simple logic to print them with below.




Quote:
echo $userlogin | awk -F ' ' '{print $13$14$15$16$17$18}'

echo $userlogin | awk -F ' ' '{print $19$20$21$22$23$24}'

echo $userlogin | awk -F ' ' '{print $25$26$27$28$29$30}'

echo $userlogin | awk -F ' ' '{print $25$26$27$28$29$30}'
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

2. Shell Programming and Scripting

Print all between 2 strings

Hi All, I'm working on a large file and need to extract all data between 2 strings. I have seen many good solutions to threads almost like my problem but none that quite fit. This is all very new to me so any ideas would be really appreciated! (attempted to read sed and awk tutorials but got a... (9 Replies)
Discussion started by: soots
9 Replies

3. Shell Programming and Scripting

Print all the lines between 2 specified strings

Hi All, I have a file in which i want to print all the lines between 2 defined strings. Ex- I have file with data as follows STEP1:- ----- has some 20 -30 lines of data STEP2:- ----- has some 20 -30 lines of data So i want to print those lines between STEP1 & STEP2. (line including STEP1)... (7 Replies)
Discussion started by: digitalrg
7 Replies

4. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

5. Shell Programming and Scripting

print specific strings only

Hello, I have a file like this.. 2 168611167 STK39 STK39 --- 27347 "serine threonine kinase 39 (STE20/SPS1 homolog, yeast)" YES SNP_A-2086192 rs16854601 0.001558882 6 13670256 SIRT5 /// RPS4X SIRT5 --- 23408 /// 6191 "sirtuin (silent mating type... (5 Replies)
Discussion started by: genehunter
5 Replies

6. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

7. UNIX for Dummies Questions & Answers

Get strings on a file and print

hi all! i have a file like this lea 25 female dave 18 male jake 27 male and i want to have an output file like this my name is lea. i am 25. female my name is dave. i am 18. male my name is jake. i am 27. male thanks! (2 Replies)
Discussion started by: engr.jay
2 Replies

8. Shell Programming and Scripting

[Help me!] print text between two strings

Deal All, I have problem for this: input file : "data.txt" R 240 585694.59946146.8 8.0 239 585694.09946134.3 8.0 238 585693.59946121.8 8.01R 237 585693.09946109.3 8.0 236 585692.59946096.9 8.0 235 585692.19946084.4 8.01R 234 585691.59946071.9 8.0 233 585691.09946059.5 8.0 232... (2 Replies)
Discussion started by: aksin
2 Replies

9. Shell Programming and Scripting

[Help me!] Print text between two strings

Deal All, I have problem for this: input file : "data.txt" R 240 585694.59946146.8 8.0 239 585694.09946134.3 8.0 238 585693.59946121.8 8.01R 237 585693.09946109.3 8.0 236 585692.59946096.9 8.0 235 585692.19946084.4 8.01R 234 585691.59946071.9 8.0 233 585691.09946059.5 8.0 232... (2 Replies)
Discussion started by: aksin
2 Replies

10. Shell Programming and Scripting

Using arrays in bash using strings to bash built-in true

I have the following code and for some reason when I call the program using /home/tcdata/tatsh/trunk/hstmy/bin/bash/raytrac.bash --cmod=jcdint.cmod I get hasArgument = hasArgument = true Somehow the array element is returning even though I have not chosen the option. ... (41 Replies)
Discussion started by: kristinu
41 Replies
CGI::Application::Plugin::FormState(3pm)		User Contributed Perl Documentation		  CGI::Application::Plugin::FormState(3pm)

NAME
CGI::Application::Plugin::FormState - Store Form State without Hidden Fields VERSION
Version 0.12 SYNOPSIS
FormState is just a temporary stash that you can use for storing and retrieving private parameters in your multi-page form. use CGI::Application::Plugin::FormState; my $form = <<EOF; <form action="app.cgi"> <input type="hidden" name="run_mode" value="form_process_runmode"> <input type="hidden" name="cap_form_state" value="<tmpl_var cap_form_state>"> ... </form> EOF sub form_display_runmode { my $self = shift; # Store some parameters $self->form_state->param('name' => 'Road Runner'); $self->form_state->param('occupation' => 'Having Fun'); my $t = $self->load_tmpl(scalarref => $form); return $t->output; } sub form_process_runmode { my $self = shift; # Retrieve some parameters print $self->form_state->param('name'); # 'Road Runner' print $self->form_state->param('occupation'); # 'Having Fun' } EXAMPLE
This is a more complete example, using CGI::Application::Plugin::ValidateRM. use CGI::Application::Plugin::Session; use CGI::Application::Plugin::FormState; use CGI::Application::Plugin::ValidateRM; my $form = <<EOF; <form action="app.cgi"> <input type="hidden" name="run_mode" value="my_form_process"> <input type="hidden" name="cap_form_state" value="<tmpl_var cap_form_state>"> ... </form> EOF sub my_form_display { my $self = shift; my $errs = shift; my $t = $self->load_tmpl(scalarref => $form); # Stash some data into it $self->form_state->param('name' => 'Wile E. Coyote'); $self->form_state->param('occupation' => 'Mining Engineer'); # Normal ValidateRM error handling $t->param($errs) if $errs; return $t->output; } sub my_form_process { my $self; # Normal ValidateRM validation my ($results, $err_page) = $self->check_rm('my_form_display','_my_form_profile'); return $err_page if $err_page; # The data from the submitted form my $params = $self->dfv_results; $params->{'name'} = $self->form_state->param('name'); # 'Wile E. Coyote' $params->{'occupation'} = $self->form_state->param('occupation'); # 'Mining Engineer' # Now do something interesting with $params # ... my $t = $self->load_tmpl('success.html'); return $t->output; } # Standard ValiateRM profile sub _my_form_profile { return { required => 'email', msgs => { any_errors => 'some_errors', prefix => 'err_', }, }; } DESCRIPTION
"CGI::Application::Plugin::FormState" provides a temporary storage area within the user's session for storing form-related data. The main use of this is for multi-page forms. Instead of using hidden fields to store data related to the form, you store and retrieve values from the form state. In the first instance of your app: $self->form_state->param('some_name' => 'some_value'); $self->form_state->param('some_other_name' => 'some_other_value'); And later, in a different instance of your app: $val1 = $self->form_state->param('some_name'); $val2 = $self->form_state->param('some_other_name'); To connect the first instance and the second, you put a single hidden field in your template: <input type="hidden" name="cap_form_state" value="<tmpl_var my_storage_name>"> You don't have to worry about creating the template param "cap_form_state"; it is added automatically to your template parameters via the "load_tmpl" hook. If you want to use a parameter other than "cap_form_state" you can do so via the "name" parameter to "form_state-"config>. If you're skeptical about whether all this abstraction is a good idea, see "MOTIVATION", below. PRESERVING FORM STATE ACROSS REDIRECTS
You can include the form_state hash in a link: my $link = '/app.cgi?rm=list&cap_form_state=' . $self->form_state->id; If you use CGI::Application::Plugin::Redirect, you can easily create redirect this way: $self->redirect('/app.cgi?rm=list&cap_form_state=' . $self->form_state->id); If you also use CGI::Application::Plugin::LinkIntegrity it is as simple as: $self->redirect($self->link('/app.cgi', 'rm' => 'list', 'cap_form_state' => $self->form_state->id)); Or, in the case of a link to the currently running app: $self->redirect($self->self_link('rm' => 'list', 'cap_form_state' => $self->form_state->id)); IMPLEMENTATION
When you call "$self->form_state" for the first time, a top-level key is created in the user's session. This key contains a random, hard- to-guess element. It might look something like: form_state_cap_form_state_84eb13cfed01764d9c401219faa56d53 All data you place in the form state with "param" is stored in the user's session under this key. You pass the name of this key on to the next instance of your application by means of a hidden field in your form: <input type="hidden" name="cap_form_state" value="<tmpl_var cap_form_state>"> You manually put this hidden field in your template. The template parameter "cap_form_state" is automatically added to your template parameters via the "load_tmpl" hook. It contains the random, hard-to-guess portion (e.g. "84eb13cfed01764d9c401219faa56d53"). When the template is filled, the hidden field will look something like this: <input type="hidden" name="cap_form_state" value="84eb13cfed01764d9c401219faa56d53"> Since all values are stored on the server in the user's session, the user can't tamper with any of them. To keep old form_data from cluttering up the user's session, the system uses CGI::Session's "expire" feature to expire old form state keys after a reasonable amount of time has passed (2 days by default). You can manually delete a form state storage by calling: $self->form_state->delete; METHODS
config(%options) Sets defaults for the plugin. Calling config is purely optional, since the defaults should be fine most purposes. $self->form_state->config('name' => 'storage_names', 'expires' => '3d') The following options are allowed: name Sets the name of the default form state storage. This name is used for the key in the user's session, for the name of hidden form field, and the template parameter used to fill the hidden form field. So if you set the "name" to "foo": $self->form_state_config('name' => 'foo'); then the hidden field in your template should look like this: <input type="hidden" name="foo" value="<tmpl_var foo>"> and the key in the user's session would look something like this: form_state_foo_84eb13cfed01764d9c401219faa56d53 expires Indicates when form state storage keys should expire and disappear from the user's session. Uses the same format as CGI::Session's "expire". Defaults to 2 days ('2d'). To cancel expiration and make the form state last as long as the user's session does, use: $self->form_state_config('expires' => 0); param Read and set values in the form state storage. It acts like the "param" method typically does in modules such as CGI, CGI::Application, CGI::Session, "HTML::Template" etc. # set a value $self->form_state->param('some_name' => 'some_value'); # retrieve a value my $val = $self->form_state->param('some_name'); # set multiple values $self->form_state->param( 'some_name' => 'some_value', 'some_other_name' => 'some_other_value', ); # retrive the names of all the keys my @keys = $self->form_state->param; clear_params Clear all of the values in the form state storage: $self->form_state->param('name' => 'Road Runner'); $self->form_state->clear_params; print $self->form_state->param('name'); # undef delete Deletes the form_state storage from the user's session. id Returns the current value of the storage param - the "hard to guess" portion of the session key. my $id = $self->form_state->id; name Returns the current name being used for storage. Defaults to "cap_form_state". my $name = $self->form_state->name; session_key Returns the full key used for storage in the user's session. my $key = $self->form_state->session_key; # Get the full form state hash my $data = $self->session->param($key); The following can be used to debug the form_state data: use Data::Dumper; print STDERR Dumper $self->session->param($self->form_state->session_key); MOTIVATION
Why not just use hidden fields? Hidden fields are not secure. The end user could save a local copy of your form, change the hidden fields and tamper with your app's form state. Why not just use the user's session? With "CGI::Application::Plugin::FormState" the data is associated with a particular instance of a form, not with the user. If the user gives up halfway through your multi-page form, you don't want their session to be cluttered up with the incomplete form state data. If a user opens up your application in two browser windows (both sharing the same user session), each window should have it's own independent form state. For instance, in an email application the user might have one window open for the inbox and another open for the outbox. If you store the value of "current_mailbox" in the user's session, then one of these windows will go to the wrong mailbox. Finally, the user's session probably sticks around longer than the form state should. AUTHOR
Michael Graham, "<mag-perl@occamstoothbrush.com>" BUGS
Please report any bugs or feature requests to "bug-cgi-application-plugin-formstate@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. ACKNOWLEDGEMENTS
Thanks to Richard Dice and Cees Hek for helping me sort out the issues with this approach. The informative error message text used for when this module is loaded before your app actually @ISA "CGI::Application" object was stolen from Cees's CGI::Application::Plugin::TT module. COPYRIGHT &; LICENSE Copyright 2005 Michael Graham, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-11-10 CGI::Application::Plugin::FormState(3pm)
All times are GMT -4. The time now is 04:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy