Sponsored Content
Top Forums Shell Programming and Scripting Questions related to if in awk context and if without awk context Post 303029690 by Seth on Wednesday 30th of January 2019 07:51:14 PM
Old 01-30-2019
Questions related to if in awk context and if without awk context

I wrote this code, questions follow


Code:
#! /bin/bash -f 

 # Purpose - to show how if syntax is used within an awk
  clear;
  ls -l;

  echo "This will print out the first two columns of the inputted file in this directory";
  echo "Enter filename found in this directory";
  read input;
  awk '{if($input == echo$(ls)) 
         {
          print $1 "\t" $2;
         }
         else
          {
          echo "file " $input " not in this Directory";
          exit
          }
       }' $input


Question 1 - how would I write this better so that my commands are executed under the else statement instead of getting a fatal error when $input is not a file in the Directory?


Question 2 - how would I represent this if statement outside this script and not within an awk command? When using if [ $input == echo$(ls) ] or if [[ $input == echo$(ls) ]]
where $input is a file name in the Directory I get a "too many arguments" and false return or just a false return respectively.



Thank you in advance.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Context Switching

I know that this is a relative question but can someone give me an idea of what would be considered a high number of context switches? I am running vmstat and show a cs value of between 5000 and 6000 on a 4 processor system. How can I deduce if this number is high or not? Also, the timeslice... (2 Replies)
Discussion started by: keelba
2 Replies

2. Shell Programming and Scripting

keep context in awk

here is a data file. ------------------------------------- KSH, CSH, BASH, PERL, PHP, SED, AWK KSH, CSH, BASH, PERL, PHP, BASH, PERL, PHP, SED, AWK CSH, BASH, PERL, PHP, SED, KSH, CSH, BASH, PERL, PHP, SED, AWK ------------------------------------- My desired output is... (2 Replies)
Discussion started by: VTAWKVT
2 Replies

3. UNIX for Advanced & Expert Users

context lost problem

there are several same servers(process) on more than one server(machine) providing the same service. we store session/context within the server(process), if the same client login, he will be directed to the very server service for him last time. But, if a server(machine or process) down, the... (1 Reply)
Discussion started by: zhongyj
1 Replies

4. Shell Programming and Scripting

grep help after context

Hi, There's a file with below contents which I have to read based on the input parameter provided by the user. FILE_ID=1 FILE_FTP_ID=ftp.server1.com FILE_FTP_USER=user1 FILE_FTP_PASS=pass1 FILE_ID=2 FILE_FTP_ID=ftp.server2.com FILE_FTP_USER=user2 FILE_FTP_PASS=pass2 FILE_ID=3... (6 Replies)
Discussion started by: dips_ag
6 Replies

5. UNIX for Dummies Questions & Answers

Split based on Context

Hello, I have a file that I want to be able to split at specific positions. For example in the file below I want to be able to split at every occurence of 2 at the start of a line, into multiple files. 2 abc PQRST abcRSTG 2 cde FGKL abcLKGRG ABCLKgrg 2 lmn OPT lmopqrst uvwxyz ... (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

6. UNIX for Dummies Questions & Answers

Context-switching question

Hi all, I've got this question that i need to solve: "Type `vmstat -s; vmstat -n 1 5; vmstat -n 1 5; vmstat -s` to your Ruby interpreter. Then terminate your Ruby session. Run the Unix com- mand vmstat -s; vmstat -n 1 5; vmstat -s in the same terminal window you had been using for Ruby. Did... (1 Reply)
Discussion started by: snowboarder
1 Replies

7. Slackware

Context dependent symlinks

Ive got multiple PCs, sharing an NFS mounted home dir. For certain apps I would like to keep the config files host specific. Easy solution is to create symlinks to local folders for configs. Ideally I would still want the .config files to reside in the user home folder. Is it possible to... (2 Replies)
Discussion started by: agentrnge
2 Replies

8. Linux

involuntary context switching

In a kernel based on 2.6.27: In the schedule() routine they have a local variable switch_count: /* * schedule() is the main scheduler function. */ asmlinkage void __sched schedule(void) { struct task_struct *prev, *next; unsigned long *switch_count; struct rq... (2 Replies)
Discussion started by: chriskot
2 Replies

9. UNIX for Advanced & Expert Users

Interupt Context Switching

If suppose a middle level interrupt is being serviced and a high priority interrupts comes in then in that case what all process will take place. The interrupt context switch will happen. But where will the interrupt context be saved? Is there something called as part process data area? (4 Replies)
Discussion started by: rupeshkp728
4 Replies

10. Shell Programming and Scripting

Context for use of [.symbol.] awk notation

Hi Just wondering ... do you have an example of context that would demonstrates how usefull the awk notation can efficiently be used ? Thx :rolleyes: (6 Replies)
Discussion started by: ctsgnb
6 Replies
LOCALE_GET_DISPLAY_VARIANT(3)						 1					     LOCALE_GET_DISPLAY_VARIANT(3)

Locale::getDisplayVariant - Returns an appropriately localized display name for variants of the input locale

	Object oriented style

SYNOPSIS
publicstatic string Locale::getDisplayVariant (string $locale, [string $in_locale]) DESCRIPTION
Procedural style string locale_get_display_variant (string $locale, [string $in_locale]) Returns an appropriately localized display name for variants of the input locale. If is NULL then the default locale is used. PARAMETERS
o $locale - The locale to return a display variant for o $in_locale - Optional format locale to use to display the variant name RETURN VALUES
Display name of the variant for the $locale in the format appropriate for $in_locale. EXAMPLES
Example #1 locale_get_display_variant(3) example <?php echo locale_get_display_variant('sl-Latn-IT-nedis', 'en'); echo "; "; echo locale_get_display_variant('sl-Latn-IT-nedis', 'fr'); echo "; "; echo locale_get_display_variant('sl-Latn-IT-nedis', 'de'); ?> Example #2 OO example <?php echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'en'); echo "; "; echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'fr'); echo "; "; echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'de'); ?> The above example will output: Natisone dialect; dialecte de Natisone; NEDIS SEE ALSO
locale_get_display_name(3), locale_get_display_language(3), locale_get_display_script(3), locale_get_display_region(3). PHP Documentation Group LOCALE_GET_DISPLAY_VARIANT(3)
All times are GMT -4. The time now is 12:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy